Class: MotionGradle::Template

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Template

Returns a new instance of Template.



5
6
7
8
# File 'lib/motion_gradle/template.rb', line 5

def initialize(name)
  template_path = File.expand_path("../templates/#{name}.erb", __FILE__)
  @template = ERB.new(File.new(template_path).read)
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



3
4
5
# File 'lib/motion_gradle/template.rb', line 3

def destination
  @destination
end

Instance Method Details

#write(locals = {}) ⇒ Object



10
11
12
13
14
15
# File 'lib/motion_gradle/template.rb', line 10

def write(locals = {})
  File.open(self.destination, 'w') do |io|
    struct = OpenStruct.new(locals)
    io.puts(@template.result(struct.instance_eval { binding }))
  end
end