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
-
#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
#attribute?(attr_name) ⇒ Boolean Also known as: has_attribute?
Check if the context instance has an attribute
90 91 92 |
# File 'lib/active_interactor/context/attributes.rb', line 90 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
80 81 82 |
# File 'lib/active_interactor/context/attributes.rb', line 80 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.errors) 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
107 108 109 110 111 112 113 114 |
# File 'lib/active_interactor/context/attributes.rb', line 107 def merge!(context) merge_errors!(context.errors) if context.respond_to?(:errors) copy_flags!(context) context.each_pair do |key, value| public_send("#{key}=", value) unless value.nil? end self end |