Module: Tap::Generator::Generate
- Extended by:
- Lazydoc::Attributes
- Defined in:
- lib/tap/generator/generate.rb
Overview
::mixin run generators
A mixin defining how to run manifest actions.
Class Method Summary collapse
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.
- #to_spec ⇒ Object
Class Method Details
Instance Method Details
#action ⇒ Object
Returns :generate
77 78 79 |
# File 'lib/tap/generator/generate.rb', line 77 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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tap/generator/generate.rb', line 22 def directory(target, ={}) target = path(target) case when target == Dir.pwd when File.exists?(target) log_relative :exists, target else log_relative :create, target FileUtils.mkdir_p(target, :mode => 0755) 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.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tap/generator/generate.rb', line 44 def file(target, ={}) source_file = Tempfile.new('generate') yield(source_file) if block_given? source_file.close source = source_file.path target = path(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, :mode => 0755) unless File.exists?(dir) FileUtils.mv(source, target, :force => true) FileUtils.chmod(0644, target) end target end |
#to_spec ⇒ Object
81 82 83 84 85 |
# File 'lib/tap/generator/generate.rb', line 81 def to_spec spec = super spec['mixin'] = 'Tap::Generator::Generate' spec end |