class Filegen::Data
This class is used as context for the erb-template
Attributes
data_sources[R]
Public Class Methods
new(data_sources)
click to toggle source
Create context class
@param [Array,DataSource] data_sources
The data sources which should be available for variable lookup
# File lib/filegen/data.rb, line 16 def initialize(data_sources) @data_sources = Array(data_sources) end
Public Instance Methods
instance_binding()
click to toggle source
Make the binding of the class available @return [Binding]
# File lib/filegen/data.rb, line 32 def instance_binding binding end
lookup(variable, default_value = '')
click to toggle source
Lookup a variable within the data sources
@param [String] variable
The variable to lookup
@return [String]
The value of the variable
# File lib/filegen/data.rb, line 26 def lookup(variable, default_value = '') try_to_fetch_unless_found_or_end(variable) || default_value end
Private Instance Methods
try_to_fetch_unless_found_or_end(variable)
click to toggle source
# File lib/filegen/data.rb, line 38 def try_to_fetch_unless_found_or_end(variable) result = nil data_sources.each do |s| (result = s.fetch(variable)) && (return result) end nil end