Class: RubyUIAdmin::ExecutionContext
- Inherits:
-
Object
- Object
- RubyUIAdmin::ExecutionContext
show all
- Defined in:
- lib/ruby_ui_admin/execution_context.rb
Overview
Evaluates a value that may be a literal or a Proc. When it's a Proc, it's
instance_exec'd with all the passed keyword arguments available as readers.
ExecutionContext.new(target: -> { record.name }, record: post).handle
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ExecutionContext.
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/ruby_ui_admin/execution_context.rb', line 9
def initialize(**args)
@target = args.delete(:target)
@view_context = args.delete(:view_context)
@args = args
args.each do |key, value|
define_singleton_method(key) { value }
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
26
27
28
29
30
|
# File 'lib/ruby_ui_admin/execution_context.rb', line 26
def method_missing(name, *args, **kwargs, &block)
return super unless @view_context.respond_to?(name)
@view_context.public_send(name, *args, **kwargs, &block)
end
|
Instance Method Details
#handle ⇒ Object
20
21
22
23
24
|
# File 'lib/ruby_ui_admin/execution_context.rb', line 20
def handle
return @target unless @target.respond_to?(:call)
instance_exec(&@target)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
32
33
34
|
# File 'lib/ruby_ui_admin/execution_context.rb', line 32
def respond_to_missing?(name, include_private = false)
(@view_context&.respond_to?(name)) || super
end
|