Class: YTools::Templates::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/ytools/templates/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template = nil, yaml_object = nil) ⇒ Executor

Returns a new instance of Executor.



9
10
11
12
# File 'lib/ytools/templates/executor.rb', line 9

def initialize(template=nil, yaml_object=nil)
  @template = template
  @yaml_object = yaml_object
end

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



7
8
9
# File 'lib/ytools/templates/executor.rb', line 7

def template
  @template
end

#yaml_objectObject (readonly)

Returns the value of attribute yaml_object.



7
8
9
# File 'lib/ytools/templates/executor.rb', line 7

def yaml_object
  @yaml_object
end

Instance Method Details

#execute!(yaml_files, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/ytools/templates/executor.rb', line 14

def execute!(yaml_files, options)
  @template = options[:erb]
  @yaml_object = options[:yaml_object]

  if options[:debug]
    STDERR.puts @yaml_object.to_s
  end
  
  write!(options[:output])
end

#write!(outfile) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/ytools/templates/executor.rb', line 25

def write!(outfile)
  generator = ERB.new(template)
  output = generator.result(yaml_object.erb_binding)

  if outfile
    File.open(outfile, 'w') {|f| f.write(output)}
  else
    puts output
  end
end