Class: LucidComponent::AppStoreDefaults
- Inherits:
-
Object
- Object
- LucidComponent::AppStoreDefaults
- Defined in:
- lib/lucid_component/app_store_defaults.rb
Instance Method Summary collapse
-
#initialize(state, component_name) ⇒ AppStoreDefaults
constructor
A new instance of AppStoreDefaults.
- #method_missing(key, *args, &block) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(state, component_name) ⇒ AppStoreDefaults
Returns a new instance of AppStoreDefaults.
3 4 5 6 7 8 9 10 |
# File 'lib/lucid_component/app_store_defaults.rb', line 3 def initialize(state, component_name) @state = state if @state.isomorfeus_store @state.isomorfeus_store.merge!(application_state: {}) else @state.isomorfeus_store = { application_state: {}} end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lucid_component/app_store_defaults.rb', line 12 def method_missing(key, *args, &block) if `args.length > 0` # set initial class state key = key.chop if `key.endsWith('=')` @state.isomorfeus_store[:application_state][key] = args[0] current_state = Isomorfeus.store.get_state if !(current_state[:application_state].key?(key)) Isomorfeus.store.dispatch(type: 'APPLICATION_STATE', name: key, value: args[0]) end else # get class state # check if we have a component local state value if @state.isomorfeus_store[:application_state].key?(key) return @state.isomorfeus_store[:application_state][key] end end nil end |
Instance Method Details
#to_h ⇒ Object
32 33 34 |
# File 'lib/lucid_component/app_store_defaults.rb', line 32 def to_h @state.isomorfeus_store[:application_state] end |