Class: Pagify::Helper::Setting
- Inherits:
-
Object
- Object
- Pagify::Helper::Setting
- Defined in:
- lib/pagify/helper/detail/setting.rb
Overview
TODO: refactor me!!
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #additional_attributes ⇒ Object
-
#initialize(helper, parent = {}) ⇒ Setting
constructor
A new instance of Setting.
- #restore_default! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(helper, parent = {}) ⇒ Setting
Returns a new instance of Setting.
8 9 10 11 12 |
# File 'lib/pagify/helper/detail/setting.rb', line 8 def initialize helper, parent = {} @helper = helper @parent = parent @attributes = extract_default_attributes helper end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/pagify/helper/detail/setting.rb', line 14 def [] key if @attributes.key?(key) @attributes[key] else @parent[key] end end |
#[]=(key, value) ⇒ Object
22 23 24 |
# File 'lib/pagify/helper/detail/setting.rb', line 22 def []= key, value @attributes[key] = value end |
#additional_attributes ⇒ Object
34 35 36 37 38 39 |
# File 'lib/pagify/helper/detail/setting.rb', line 34 def additional_attributes defaults = extract_default_attributes( @helper.kind_of?(Abstract) ? @helper.class : @helper).keys @parent.to_hash.merge(@attributes).reject{ |key, value| defaults.member?(key) } end |
#restore_default! ⇒ Object
30 31 32 |
# File 'lib/pagify/helper/detail/setting.rb', line 30 def restore_default! @attributes = extract_default_attributes @helper end |
#to_hash ⇒ Object
26 27 28 |
# File 'lib/pagify/helper/detail/setting.rb', line 26 def to_hash @attributes.dup end |