Class: ExtractItems

Inherits:
Object
  • Object
show all
Includes:
Interpipe::Interactor
Defined in:
app/interactors/extract_items.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Interpipe::Interactor

included, #initialize, #setup

Class Attribute Details

.attributeObject

Returns the value of attribute attribute


18
19
20
# File 'app/interactors/extract_items.rb', line 18

def attribute
  @attribute
end

.collectionObject

Returns the value of attribute collection


18
19
20
# File 'app/interactors/extract_items.rb', line 18

def collection
  @collection
end

.result_keyObject

Returns the value of attribute result_key


18
19
20
# File 'app/interactors/extract_items.rb', line 18

def result_key
  @result_key
end

Class Method Details

.[](result_key, from:, attr:) ⇒ Object


20
21
22
23
24
25
26
# File 'app/interactors/extract_items.rb', line 20

def [](result_key, from:, attr:)
  Class.new(self).tap do |cls|
    cls.collection = from
    cls.attribute = attr
    cls.result_key = result_key
  end
end

Instance Method Details

#perform(**options) ⇒ Object


6
7
8
9
10
11
# File 'app/interactors/extract_items.rb', line 6

def perform(**options)
  @options = options
  collection = options[collection_key]
  raise "#{self.class.name}: Missing collection key '#{collection_key}'." unless collection
  @items = collection.map { |item| item.send(attribute) }.reject(&:nil?).uniq { |i| i.link_id }
end

#resultsObject


13
14
15
# File 'app/interactors/extract_items.rb', line 13

def results
  { result_key => @items }.merge(@options)
end