Module: SnowyOwl::Props

Defined in:
lib/snowy_owl/props.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



18
19
20
21
22
# File 'lib/snowy_owl/props.rb', line 18

def method_missing(name, *args, &block)
  @__props__ ||= init_props
  return @__props__.send name if @__props__.respond_to? name
  super name, *args, &block
end

Instance Method Details

#init_propsObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/snowy_owl/props.rb', line 7

def init_props
  props_path = SnowyOwl.props_path
  raise 'Invalid props path' if props_path.empty?
  props_hash = {}
  Dir[props_path].each do |f|
    field_name = File.basename f, '.yml'
    props_hash[field_name] = YAML.load_file(f)
  end
  @__props__ = JSON.parse(props_hash.to_json, object_class: OpenStruct)
end