Class: Backup::Template
- Inherits:
-
Object
- Object
- Backup::Template
- Defined in:
- lib/backup/template.rb
Instance Attribute Summary collapse
-
#binding ⇒ Object
Holds a binding object.
Instance Method Summary collapse
-
#initialize(object = nil) ⇒ Template
constructor
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.
-
#render(file) ⇒ Object
Renders the provided file (in the context of the binding if any) to the console.
-
#result(file) ⇒ Object
Returns a String object containing the contents of the file (in the context of the binding if any).
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
14 15 16 17 18 19 20 21 22 |
# File 'lib/backup/template.rb', line 14 def initialize(object = nil) if object.is_a?(Binding) @binding = object elsif object.is_a?(Hash) @binding = Backup::Binder.new(object).get_binding else @binding = nil end end |
Instance Attribute Details
#binding ⇒ Object
Holds a binding object. Nil if not provided.
9 10 11 |
# File 'lib/backup/template.rb', line 9 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
26 27 28 |
# File 'lib/backup/template.rb', line 26 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)
32 33 34 |
# File 'lib/backup/template.rb', line 32 def result(file) ERB.new(file_contents(file), nil, '<>').result(binding) end |