Class: Tailmix::Runtime::StateProxy
- Inherits:
-
Object
- Object
- Tailmix::Runtime::StateProxy
- Defined in:
- lib/tailmix/runtime/state_proxy.rb
Overview
Proxy for convenient access to the component state (ui.state).
Instance Method Summary collapse
-
#initialize(context) ⇒ StateProxy
constructor
A new instance of StateProxy.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(context) ⇒ StateProxy
Returns a new instance of StateProxy.
7 8 9 |
# File 'lib/tailmix/runtime/state_proxy.rb', line 7 def initialize(context) @context = context end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tailmix/runtime/state_proxy.rb', line 11 def method_missing(method_name, *args, &block) state_key = method_name.to_s.chomp("=").to_sym # We are checking if this state is defined in the DSL. unless @context.definition.states.key?(state_key) raise NoMethodError, "undefined state `#{state_key}` for #{@context.component_name}" end if method_name.end_with?("=") # This is a setter: ui.state.open = true @context.set_state(state_key, args.first) else # This is a getter: ui.state.open @context.get_state(state_key) end end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
28 29 30 31 |
# File 'lib/tailmix/runtime/state_proxy.rb', line 28 def respond_to_missing?(method_name, include_private = false) state_key = method_name.to_s.chomp("=").to_sym @context.definition.states.key?(state_key) || super end |