Module: DataSet::DataAccessor
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/data_set/data_accessor.rb', line 5
def method_missing(*args, &block)
load_data_source unless @data_contents
key = args.first
value = @data_contents[key.to_s]
value = args[1] if value.nil?
value = yield(key.to_s) if value.nil? && block
super if value.nil?
value = DataSet::DataElement.new(value) unless type_known?(value)
value
end
|
Instance Method Details
#load_data_source ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/data_set/data_accessor.rb', line 20
def load_data_source
@data_contents = nil
path = "#{data_path}/#{ENV['DATA_SET_FILE']}"
if ENV['DATA_SET_FILE']
@data_contents = ::YAML.safe_load(ERB.new(
File.read(path)
).result(binding))
end
DataSet.load('default.yml') if @data_contents.nil?
end
|
#respond_to_missing?(*args) ⇒ Boolean
16
17
18
|
# File 'lib/data_set/data_accessor.rb', line 16
def respond_to_missing?(*args)
super
end
|