Sha256: bf265f2a543b0c769236aa3ae606237786d3735cfc494612f841b5e0a1c7042b
Contents?: true
Size: 1 KB
Versions: 7
Compression:
Stored size: 1 KB
Contents
# encoding: utf-8 # Main Class module Filegen # This class is used as context for the erb-template class Data private attr_reader :data_sources public # Create context class # # @param [Array,DataSource] data_sources # The data sources which should be available for variable lookup def initialize(data_sources) @data_sources = Array(data_sources) end # Lookup a variable within the data sources # # @param [String] variable # The variable to lookup # @return [String] # The value of the variable def lookup(variable, default_value = '') try_to_fetch_unless_found_or_end(variable) || default_value end # Make the binding of the class available # @return [Binding] def instance_binding binding end private 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 end end
Version data entries
7 entries across 7 versions & 1 rubygems