Class: Avo::ExecutionContext
- Inherits:
-
Object
- Object
- Avo::ExecutionContext
- Includes:
- Concerns::HasHelpers
- Defined in:
- lib/avo/execution_context.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#avo ⇒ Object
Returns the value of attribute avo.
-
#context ⇒ Object
Returns the value of attribute context.
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#include ⇒ Object
Returns the value of attribute include.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#main_app ⇒ Object
Returns the value of attribute main_app.
-
#params ⇒ Object
Returns the value of attribute params.
-
#request ⇒ Object
Returns the value of attribute request.
-
#target ⇒ Object
Returns the value of attribute target.
-
#view_context ⇒ Object
Returns the value of attribute view_context.
Instance Method Summary collapse
-
#handle ⇒ Object
Return target if target is not callable, otherwise, execute target on this instance context.
-
#initialize(**args) ⇒ ExecutionContext
constructor
A new instance of ExecutionContext.
Methods included from Concerns::HasHelpers
Constructor Details
#initialize(**args) ⇒ ExecutionContext
Returns a new instance of ExecutionContext.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/avo/execution_context.rb', line 9 def initialize(**args) # Extend the class with custom modules if required. if args[:include].present? args[:include].each do |mod| self.class.send(:include, mod) end end # If target doesn't respond to call, we don't need to initialize the others attr_accessors. return unless (@target = args[:target]).respond_to? :call args.except(:target).each do |key, value| singleton_class.class_eval { attr_accessor key } instance_variable_set("@#{key}", value) end # Set defaults on not initialized accessors @context ||= Avo::Current.context @current_user ||= Avo::Current.user @params ||= Avo::Current.params @request ||= Avo::Current.request @view_context ||= Avo::Current.view_context @locale ||= Avo::Current.locale @main_app ||= @view_context&.main_app @avo ||= @view_context&.avo end |
Instance Attribute Details
#avo ⇒ Object
Returns the value of attribute avo.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def avo @avo end |
#context ⇒ Object
Returns the value of attribute context.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def context @context end |
#current_user ⇒ Object
Returns the value of attribute current_user.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def current_user @current_user end |
#include ⇒ Object
Returns the value of attribute include.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def include @include end |
#locale ⇒ Object
Returns the value of attribute locale.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def locale @locale end |
#main_app ⇒ Object
Returns the value of attribute main_app.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def main_app @main_app end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def params @params end |
#request ⇒ Object
Returns the value of attribute request.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def request @request end |
#target ⇒ Object
Returns the value of attribute target.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def target @target end |
#view_context ⇒ Object
Returns the value of attribute view_context.
5 6 7 |
# File 'lib/avo/execution_context.rb', line 5 def view_context @view_context end |
Instance Method Details
#handle ⇒ Object
Return target if target is not callable, otherwise, execute target on this instance context
40 41 42 |
# File 'lib/avo/execution_context.rb', line 40 def handle target.respond_to?(:call) ? instance_exec(&target) : target end |