Module: ActiveInteractor::Context::Attributes
- Included in:
- Base
- Defined in:
- lib/active_interactor/context/attributes.rb
Overview
Context attribute methods. Because Attributes is a module classes should include Attributes rather than inherit from it.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns the value of an attribute.
-
#[]=(name, value) ⇒ Object
Sets value of a Hash attribute in context.attributes.
-
#attribute?(attr_name) ⇒ Boolean
(also: #has_attribute?)
Check if the context instance has an attribute.
-
#attributes ⇒ Hash{Symbol => *}
Get values defined on the instance of context whose keys are defined on the context class' .attributes.
-
#initialize(context = {}) ⇒ Base
Initialize a new instance of Base.
- #merge!(context) ⇒ self
Instance Method Details
#[](name) ⇒ Object
Returns the value of an attribute
68 69 70 |
# File 'lib/active_interactor/context/attributes.rb', line 68 def [](name) @table[name.to_sym] || attributes[name.to_sym] end |
#[]=(name, value) ⇒ Object
Sets value of a Hash attribute in context.attributes
79 80 81 82 83 |
# File 'lib/active_interactor/context/attributes.rb', line 79 def []=(name, value) public_send("#{name}=", value) super unless @table.nil? end |
#attribute?(attr_name) ⇒ Boolean Also known as: has_attribute?
Check if the context instance has an attribute
113 114 115 |
# File 'lib/active_interactor/context/attributes.rb', line 113 def attribute?(attr_name) @attributes.key?(attr_name.to_s) end |
#attributes ⇒ Hash{Symbol => *}
Get values defined on the instance of context whose keys are defined on the context class' .attributes
103 104 105 |
# File 'lib/active_interactor/context/attributes.rb', line 103 def attributes super.symbolize_keys end |
#initialize(context = {}) ⇒ Base
Initialize a new instance of Base
52 53 54 55 56 57 58 59 60 |
# File 'lib/active_interactor/context/attributes.rb', line 52 def initialize(context = {}) merge_errors!(context) if context.respond_to?(:errors) copy_flags!(context) copy_called!(context) context = context_attributes_as_hash(context) || {} super merge_attribute_values(context) end |
#merge!(context) ⇒ self
130 131 132 133 134 135 136 137 138 |
# File 'lib/active_interactor/context/attributes.rb', line 130 def merge!(context) merge_errors!(context) if context.respond_to?(:errors) copy_flags!(context) merged_context_attributes(context).each_pair do |key, value| self[key] = value unless value.nil? end self end |