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(owner, *attributes) ⇒ AttributeSet

Returns a new instance of AttributeSet.



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

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

Instance Method Details

#add(*attribute_args) ⇒ Object



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

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

#attribute_namesObject



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

def attribute_names
  @set.keys
end

#attributesObject



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

def attributes
  @set.values
end

#find(attribute_name) ⇒ Object



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

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

#merge(attributes) ⇒ Object



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

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