Class: Backup::Template

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object = nil) ⇒ Template

Creates a new instance of the Backup::Template class and optionally takes an argument that can be either a binding object, a Hash or nil



11
12
13
14
15
16
17
18
# File 'lib/backup/template.rb', line 11

def initialize(object = nil)
  @binding =
    if object.is_a?(Binding)
      object
    elsif object.is_a?(Hash)
      Backup::Binder.new(object).get_binding
    end
end

Instance Attribute Details

#bindingObject

Holds a binding object. Nil if not provided.



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

def binding
  @binding
end

Instance Method Details

#render(file) ⇒ Object

Renders the provided file (in the context of the binding if any) to the console



22
23
24
# File 'lib/backup/template.rb', line 22

def render(file)
  puts result(file)
end

#result(file) ⇒ Object

Returns a String object containing the contents of the file (in the context of the binding if any)



28
29
30
# File 'lib/backup/template.rb', line 28

def result(file)
  ERB.new(file_contents(file), nil, "<>").result(binding)
end