class Backup::Template
Attributes
binding[RW]
Holds a binding object. Nil if not provided.
Public Class Methods
new(object = nil)
click to toggle source
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
# 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
Public Instance Methods
render(file)
click to toggle source
Renders the provided file (in the context of the binding if any) to the console
# File lib/backup/template.rb, line 26 def render(file) puts result(file) end
result(file)
click to toggle source
Returns a String object containing the contents of the file (in the context of the binding if any)
# File lib/backup/template.rb, line 32 def result(file) ERB.new(file_contents(file), nil, '<>').result(binding) end
Private Instance Methods
file_contents(file)
click to toggle source
Reads and returns the contents of the provided file path, relative from the Backup::TEMPLATE_PATH
# File lib/backup/template.rb, line 41 def file_contents(file) File.read(File.join(Backup::TEMPLATE_PATH, file)) end