Class: Gen::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/gen/template.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTemplate

Returns a new instance of Template.



9
10
11
# File 'lib/gen/template.rb', line 9

def initialize
  @options, @attributes = {}, {}
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



7
8
9
# File 'lib/gen/template.rb', line 7

def attributes
  @attributes
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/gen/template.rb', line 7

def options
  @options
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

Raises:



13
14
15
16
17
18
19
# File 'lib/gen/template.rb', line 13

def run! options = {}
  @options = options
  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