Class: ActiveInteractor::Context::AttributeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/active_interactor/context/attribute_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(*attributes) ⇒ AttributeSet

Returns a new instance of AttributeSet.



6
7
8
9
# File 'lib/active_interactor/context/attribute_set.rb', line 6

def initialize(*attributes)
  @set = {}
  attributes.each { |attribute| @set[attribute.name] = attribute }
end

Instance Method Details

#add(*attribute_args) ⇒ Object



11
12
13
14
15
# File 'lib/active_interactor/context/attribute_set.rb', line 11

def add(*attribute_args)
  attribute_options = attribute_args.extract_options!
  attribute = Attribute.new(*attribute_args, **attribute_options)
  @set[attribute.name] = attribute
end

#attribute_namesObject



17
18
19
# File 'lib/active_interactor/context/attribute_set.rb', line 17

def attribute_names
  @set.keys
end

#attributesObject



21
22
23
# File 'lib/active_interactor/context/attribute_set.rb', line 21

def attributes
  @set.values
end

#find(attribute_name) ⇒ Object



25
26
27
# File 'lib/active_interactor/context/attribute_set.rb', line 25

def find(attribute_name)
  @set[attribute_name.to_sym]
end

#merge(attributes) ⇒ Object



29
30
31
# File 'lib/active_interactor/context/attribute_set.rb', line 29

def merge(attributes)
  attributes.each { |attribute| @set[attribute.name] = attribute }
end