Class: Tap::Generator::Base

Inherits:
Task show all
Defined in:
lib/tap/generator/base.rb

Constant Summary collapse

Constant =
Tap::Support::Constant

Constants inherited from Task

Task::DEFAULT_HELP_TEMPLATE

Instance Attribute Summary collapse

Attributes inherited from Task

#name

Attributes included from Support::Executable

#_method_name, #app, #batch, #dependencies, #on_complete_block

Attributes included from Support::Configurable

#config

Class Method Summary collapse

Instance Method Summary collapse

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_taskObject

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_dirObject

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_dirObject

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

.lazydoc(resolve = true) ⇒ Object



7
8
9
10
11
# File 'lib/tap/generator/base.rb', line 7

def lazydoc(resolve=true)
  lazydoc = super(false)
  lazydoc[self.to_s]['args'] ||= lazydoc.register_method(:manifest, Task::Args)
  super
end

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, options={})
  directory(root)
  targets.each do |target|
    directory(File.join(root, target), options)
  end
end

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

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/tap/generator/base.rb', line 55

def directory(target, options={})
  raise NotImplementedError
end

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

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/tap/generator/base.rb', line 59

def file(target, options={})
  raise NotImplementedError
end

#iterate(action) ⇒ Object

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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={}, options={})
  template_path = File.expand_path(source, template_dir)
  templater = Support::Templater.new(File.read(template_path), attributes)
  
  file(target, options) do |file| 
    file << templater.build
  end
end

#template_filesObject



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