Module: Tap::Generator::Generate

Defined in:
lib/tap/generator/generate.rb

Instance Method Summary collapse

Instance Method Details

#directory(target, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/tap/generator/generate.rb', line 8

def directory(target, options={})
  target = File.expand_path(target, target_dir)
  
  if File.exists?(target)
    log_relative :exists, target
  else
    log_relative :create, target
    file_task.mkdir(target) unless pretend
  end
end

#file(target, options = {}) {|source_file| ... } ⇒ Object

Yields:

  • (source_file)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tap/generator/generate.rb', line 19

def file(target, options={})
  source_file = Tempfile.new('generate')
  yield(source_file) if block_given?
  source_file.close
  
  source = source_file.path
  target = File.expand_path(target, target_dir)
  
  copy_file = case
  when !File.exists?(target)
    log_relative :create, target
    true
  when FileUtils.cmp(source, target)
    log_relative :exists, target
    false
  when force_file_collision?(target)
    log_relative :force, target
    true
  else
    log_relative :skip, target
    false
  end
  
  if copy_file && !pretend
    file_task.prepare(target) 
    FileUtils.mv(source, target)
  end
end

#iterate(actions) ⇒ Object



4
5
6
# File 'lib/tap/generator/generate.rb', line 4

def iterate(actions)
  actions.each {|action| yield(action) }
end