Class: ElasticRecord::Relation::Merging::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_record/relation/merging.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, other) ⇒ Merger

Returns a new instance of Merger.



16
17
18
19
# File 'lib/elastic_record/relation/merging.rb', line 16

def initialize(relation, other)
  @relation = relation
  @values = other.values
end

Instance Attribute Details

#relationObject

Returns the value of attribute relation.



14
15
16
# File 'lib/elastic_record/relation/merging.rb', line 14

def relation
  @relation
end

#valuesObject

Returns the value of attribute values.



14
15
16
# File 'lib/elastic_record/relation/merging.rb', line 14

def values
  @values
end

Instance Method Details

#mergeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/elastic_record/relation/merging.rb', line 21

def merge
  Relation::SINGLE_VALUE_METHODS.each do |name|
    value = values[name]
    relation.send("#{name}!", value) unless value.blank?
  end

  Relation::MULTI_VALUE_METHODS.each do |name|
    value = values[name]
    relation.send("#{name}!", *value) unless value.blank?
  end

  relation
end