Class: Behavior::Base
- Inherits:
-
Object
- Object
- Behavior::Base
- Defined in:
- lib/behavior.rb
Instance Method Summary collapse
Instance Method Details
#[](key) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/behavior.rb', line 23 def [](key) out = begin BehaviorConfig.find_by_key(key.to_s).value rescue NoMethodError [key][:default] end case [key][:type] when 'integer' out.to_i when 'decimal' BigDecimal.new(out.to_s) else out end end |
#all ⇒ Object
39 40 41 |
# File 'lib/behavior.rb', line 39 def all .keys end |
#meta ⇒ Object
19 20 21 |
# File 'lib/behavior.rb', line 19 def HashWithIndifferentAccess.new(YAML.load_file(Behavior::Settings.config_file)) end |
#update(attrs = {}) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/behavior.rb', line 43 def update(attrs = {}) attrs.each do |key,value| result = BehaviorConfig.find_or_create_by_key(key.to_s) result.update_attribute(:value, value) if result end end |