Class: ServerComponentHelper::SetStateDSL
- Inherits:
-
Object
- Object
- ServerComponentHelper::SetStateDSL
- Defined in:
- app/helpers/server_component_helper.rb
Instance Method Summary collapse
-
#initialize(jsrb, new_state, prev_state) ⇒ SetStateDSL
constructor
A new instance of SetStateDSL.
-
#method_missing(name, *args) ⇒ Object
rubocop:disable Style/MethodMissingSuper.
Constructor Details
#initialize(jsrb, new_state, prev_state) ⇒ SetStateDSL
Returns a new instance of SetStateDSL.
5 6 7 8 9 |
# File 'app/helpers/server_component_helper.rb', line 5 def initialize(jsrb, new_state, prev_state) @js = jsrb @new_state = new_state @prev_state = prev_state end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
rubocop:disable Style/MethodMissingSuper
12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/server_component_helper.rb', line 12 def method_missing(name, *args) if (matches = name.to_s.match(/^(.+)=$/)) @js.set! @new_state[matches[1]], args[0] elsif block_given? block_result = yield @prev_state[name] @js.set! @new_state[name], block_result else @new_state[name] end end |