Class: Tailmix::Runtime::ActionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/tailmix/runtime/action_proxy.rb

Overview

Proxy for convenient calling of actions (ui.action).

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ ActionProxy

Returns a new instance of ActionProxy.



7
8
9
# File 'lib/tailmix/runtime/action_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
# File 'lib/tailmix/runtime/action_proxy.rb', line 11

def method_missing(method_name, *args, &block)
  action_name = method_name.to_sym
  action_def = @context.definition.actions[action_name]

  unless action_def
    raise NoMethodError, "undefined action `#{action_name}` for #{@context.component_name}"
  end

  # We return an object that can be called using .call.
  # This allows you to write ui.action.save.call(payload)
  ->(payload = {}) { @context.run_action(action_def, payload) }
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/tailmix/runtime/action_proxy.rb', line 24

def respond_to_missing?(method_name, include_private = false)
  @context.definition.actions.key?(method_name.to_sym) || super
end