Class: Gen::Template
- Inherits:
-
Object
- Object
- Gen::Template
- Defined in:
- lib/gen/template.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #attribute(name, &block) ⇒ Object
- #hook(name, *args, &block) ⇒ Object
-
#initialize ⇒ Template
constructor
A new instance of Template.
- #root(dir = nil) ⇒ Object
- #run!(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Template
Returns a new instance of Template.
9 10 11 |
# File 'lib/gen/template.rb', line 9 def initialize , @attributes = {}, {} end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/gen/template.rb', line 7 def attributes @attributes end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/gen/template.rb', line 7 def end |
Instance Method Details
#attribute(name, &block) ⇒ Object
39 40 41 |
# File 'lib/gen/template.rb', line 39 def attribute name, &block @attributes[name] = yield end |
#hook(name, *args, &block) ⇒ Object
34 35 36 37 |
# File 'lib/gen/template.rb', line 34 def hook name, *args, &block proc = instance_variable_get :"@__hook_#{name}" proc.call if proc end |
#root(dir = nil) ⇒ Object
21 22 23 24 |
# File 'lib/gen/template.rb', line 21 def root dir = nil @root = dir if dir @root end |
#run!(options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/gen/template.rb', line 13 def run! = {} = raise Error, 'root directory is required. Set using #root' unless root raise Error, "invalid root directory '#{root}'" unless File.directory? root hook :init hook :run end |