Class: ActiveInteractor::Context::Base
- Inherits:
-
Object
- Object
- ActiveInteractor::Context::Base
- Extended by:
- Type::DeclerationMethods::ClassMethods
- Includes:
- Type::DeclerationMethods, ActiveModel::Validations
- Defined in:
- lib/active_interactor/context/base.rb
Overview
The base class for all context objects
Constant Summary
Constants included from Type::DeclerationMethods
Type::DeclerationMethods::Boolean
Class Method Summary collapse
Instance Method Summary collapse
- #[](attribute_name) ⇒ Object
- #[]=(attribute_name, value) ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
Methods included from Type::DeclerationMethods::ClassMethods
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
23 24 25 26 27 28 29 |
# File 'lib/active_interactor/context/base.rb', line 23 def initialize(attributes = {}) attribute_set.attributes.each do |attribute| next unless attributes.with_indifferent_access.key?(attribute.name) assign_attribute_value(attribute.name, attributes.with_indifferent_access[attribute.name]) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments) ⇒ Object (protected)
61 62 63 64 65 66 |
# File 'lib/active_interactor/context/base.rb', line 61 def method_missing(method_name, *arguments) return super unless respond_to_missing?(method_name) return assignment_method_missing(method_name, *arguments) if method_name.to_s.end_with?('=') read_attribute_value(method_name) end |
Class Method Details
.method_defined?(method_name) ⇒ Boolean
12 13 14 |
# File 'lib/active_interactor/context/base.rb', line 12 def method_defined?(method_name) attribute_set.attribute_names.include?(method_name.to_s.delete('=').to_sym) || super end |
Instance Method Details
#[](attribute_name) ⇒ Object
31 32 33 |
# File 'lib/active_interactor/context/base.rb', line 31 def [](attribute_name) read_attribute_value(attribute_name) end |
#[]=(attribute_name, value) ⇒ Object
35 36 37 |
# File 'lib/active_interactor/context/base.rb', line 35 def []=(attribute_name, value) assign_attribute_value(attribute_name, value) end |