Module: ActiveInteractor::Context::AttributeAssignment

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_interactor/context/attribute_assignment.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ Object (protected)



42
43
44
45
46
47
# File 'lib/active_interactor/context/attribute_assignment.rb', line 42

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

Instance Method Details

#[](attribute_name) ⇒ Object



16
17
18
# File 'lib/active_interactor/context/attribute_assignment.rb', line 16

def [](attribute_name)
  read_attribute_value(attribute_name)
end

#[]=(attribute_name, value) ⇒ Object



20
21
22
# File 'lib/active_interactor/context/attribute_assignment.rb', line 20

def []=(attribute_name, value)
  assign_attribute_value(attribute_name, value)
end

#initialize(attributes = {}) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/active_interactor/context/attribute_assignment.rb', line 8

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