Module: Tap::Generator::Generate
- Defined in:
- lib/tap/generator/generate.rb
Overview
:startdoc::module A mixin defining how to run manifest actions.
Instance Method Summary collapse
-
#action ⇒ Object
Returns :generate.
-
#directory(target, options = {}) ⇒ Object
Creates the target directory if it doesn’t exist.
-
#file(target, options = {}) {|source_file| ... } ⇒ Object
Creates the target file; content may be added to the file by providing block.
Instance Method Details
#action ⇒ Object
Returns :generate
66 67 68 |
# File 'lib/tap/generator/generate.rb', line 66 def action :generate end |
#directory(target, options = {}) ⇒ Object
Creates the target directory if it doesn’t exist. When pretend is true, creation is logged but does not actually happen.
No options currently affect the behavior of this method.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tap/generator/generate.rb', line 13 def directory(target, ={}) target = File.(target) case when File.exists?(target) log_relative :exists, target else log_relative :create, target FileUtils.mkdir_p(target) unless pretend end target end |
#file(target, options = {}) {|source_file| ... } ⇒ Object
Creates the target file; content may be added to the file by providing block. If the target file already exists, the new and existing content is compared and the user will be prompted for how to handle collisions. All activity is logged. When pretend is true, creation is logged but does not actually happen.
No options currently affect the behavior of this method.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tap/generator/generate.rb', line 34 def file(target, ={}) source_file = Tempfile.new('generate') yield(source_file) if block_given? source_file.close source = source_file.path target = File.(target) copy_file = true msg = case when !File.exists?(target) :create when FileUtils.cmp(source, target) :exists when force_file_collision?(target) :force else copy_file = false :skip end log_relative msg, target if copy_file && !pretend dir = File.dirname(target) FileUtils.mkdir_p(dir) unless File.exists?(dir) FileUtils.mv(source, target, :force => true) end target end |