Class: Tap::Generator::Base
Direct Known Subclasses
Generators::CommandGenerator, Generators::ConfigGenerator, Generators::GeneratorGenerator, Generators::RootGenerator, Generators::TaskGenerator
Constant Summary collapse
Constants inherited from Task
Instance Attribute Summary collapse
-
#file_task ⇒ Object
Returns the value of attribute file_task.
-
#target_dir ⇒ Object
Returns the value of attribute target_dir.
-
#template_dir ⇒ Object
Returns the value of attribute template_dir.
Attributes inherited from Task
Attributes included from Support::Executable
#_method_name, #app, #batch, #dependencies, #on_complete_block
Attributes included from Support::Configurable
Class Method Summary collapse
Instance Method Summary collapse
- #directories(root, targets, options = {}) ⇒ Object
- #directory(target, options = {}) ⇒ Object
- #file(target, options = {}) ⇒ Object
-
#initialize(config = {}, name = nil, app = App.instance) ⇒ Base
constructor
A new instance of Base.
- #iterate(action) ⇒ Object
- #log_relative(action, path) ⇒ Object
- #manifest(m, *argv) ⇒ Object
- #process(*argv) ⇒ Object
- #template(target, source, attributes = {}, options = {}) ⇒ Object
- #template_files ⇒ Object
Methods inherited from Task
execute, help, inherited, #initialize_batch_obj, #inspect, instance, intern, #log, parse, parse!, #to_s
Methods included from Support::Executable
#_execute, #batch_index, #batch_with, #batched?, #check_terminate, #depends_on, #enq, #execute, #fork, initialize, #initialize_batch_obj, #inspect, #merge, #on_complete, #reset_dependencies, #resolve_dependencies, #sequence, #switch, #sync_merge, #unbatched_depends_on, #unbatched_enq, #unbatched_on_complete
Methods included from Support::Configurable
included, #initialize_copy, #reconfigure
Constructor Details
#initialize(config = {}, name = nil, app = App.instance) ⇒ Base
Returns a new instance of Base.
24 25 26 27 28 29 |
# File 'lib/tap/generator/base.rb', line 24 def initialize(config={}, name=nil, app=App.instance) super(config, name, app) @file_task = Tap::FileTask.new @template_dir = File.dirname(self.class.source_file) + '/templates' end |
Instance Attribute Details
#file_task ⇒ Object
Returns the value of attribute file_task.
22 23 24 |
# File 'lib/tap/generator/base.rb', line 22 def file_task @file_task end |
#target_dir ⇒ Object
Returns the value of attribute target_dir.
22 23 24 |
# File 'lib/tap/generator/base.rb', line 22 def target_dir @target_dir end |
#template_dir ⇒ Object
Returns the value of attribute template_dir.
22 23 24 |
# File 'lib/tap/generator/base.rb', line 22 def template_dir @template_dir end |
Class Method Details
Instance Method Details
#directories(root, targets, options = {}) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/tap/generator/base.rb', line 63 def directories(root, targets, ={}) directory(root) targets.each do |target| directory(File.join(root, target), ) end end |
#directory(target, options = {}) ⇒ Object
55 56 57 |
# File 'lib/tap/generator/base.rb', line 55 def directory(target, ={}) raise NotImplementedError end |
#file(target, options = {}) ⇒ Object
59 60 61 |
# File 'lib/tap/generator/base.rb', line 59 def file(target, ={}) raise NotImplementedError end |
#iterate(action) ⇒ Object
51 52 53 |
# File 'lib/tap/generator/base.rb', line 51 def iterate(action) raise NotImplementedError end |
#log_relative(action, path) ⇒ Object
43 44 45 |
# File 'lib/tap/generator/base.rb', line 43 def log_relative(action, path) log(action, app.relative_filepath(Dir.pwd, path)) end |
#manifest(m, *argv) ⇒ Object
47 48 49 |
# File 'lib/tap/generator/base.rb', line 47 def manifest(m, *argv) raise NotImplementedError end |
#process(*argv) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tap/generator/base.rb', line 31 def process(*argv) actions = [] manifest(Manifest.new(actions), *argv) iterate(actions) do |action, args, block| send(action, *args, &block) end @target_dir = nil file_task.added_files end |
#template(target, source, attributes = {}, options = {}) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/tap/generator/base.rb', line 70 def template(target, source, attributes={}, ={}) template_path = File.(source, template_dir) templater = Support::Templater.new(File.read(template_path), attributes) file(target, ) do |file| file << templater.build end end |
#template_files ⇒ Object
79 80 81 82 83 84 |
# File 'lib/tap/generator/base.rb', line 79 def template_files Dir.glob(template_dir + "/**/*").sort.each do |source| target = Tap::Root.relative_filepath(template_dir, source) yield(source, target) end end |