Class: ElasticRecord::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.



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

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

Instance Attribute Details

#relationObject

Returns the value of attribute relation.



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

def relation
  @relation
end

#valuesObject

Returns the value of attribute values.



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

def values
  @values
end

Instance Method Details

#mergeObject



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

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

  relation
end

#normal_valuesObject



20
21
22
# File 'lib/elastic_record/relation/merging.rb', line 20

def normal_values
  Relation::MULTI_VALUE_METHODS + Relation::SINGLE_VALUE_METHODS
end