Class: ActiveAny::Relation::HashMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/active_any/relation/merger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, hash) ⇒ HashMerger

Returns a new instance of HashMerger.



8
9
10
11
12
13
# File 'lib/active_any/relation/merger.rb', line 8

def initialize(relation, hash)
  hash.assert_valid_keys(*Relation::VALUE_METHODS)

  @relation = relation
  @hash     = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



6
7
8
# File 'lib/active_any/relation/merger.rb', line 6

def hash
  @hash
end

#relationObject (readonly)

Returns the value of attribute relation.



6
7
8
# File 'lib/active_any/relation/merger.rb', line 6

def relation
  @relation
end

Instance Method Details

#mergeObject



15
16
17
# File 'lib/active_any/relation/merger.rb', line 15

def merge
  Merger.new(relation, other).merge
end

#otherObject



19
20
21
22
23
# File 'lib/active_any/relation/merger.rb', line 19

def other
  other = Relation.create(relation.klass)
  hash.each { |k, v| other.public_send("#{k}!", v) }
  other
end