Class: Delta

Inherits:
Object
  • Object
show all
Defined in:
lib/delta/base.rb,
lib/delta/plucker.rb,
lib/delta/identifier.rb,
lib/delta/set_operator.rb,
lib/delta/set_operator/enumerable.rb,
lib/delta/set_operator/active_record.rb

Defined Under Namespace

Classes: Identifier, Plucker, SetOperator

Instance Method Summary collapse

Constructor Details

#initialize(from:, to:, pluck: nil, keys: nil) ⇒ Delta

Returns a new instance of Delta.



2
3
4
5
6
# File 'lib/delta/base.rb', line 2

def initialize(from:, to:, pluck: nil, keys: nil)
  identifier = keys ? Identifier.new(keys) : Identifier::Null.new
  self.set = SetOperator.adapt(a: from, b: to, identifier: identifier)
  self.plucker = pluck ? Plucker.new(pluck) : Plucker::Null.new
end

Instance Method Details

#additionsObject



8
9
10
11
12
13
14
# File 'lib/delta/base.rb', line 8

def additions
  Enumerator.new do |y|
    set.subtract_a_from_b.each do |b|
      y.yield plucker.pluck(b)
    end
  end
end

#deletionsObject



27
28
29
30
31
32
33
# File 'lib/delta/base.rb', line 27

def deletions
  Enumerator.new do |y|
    set.subtract_b_from_a.each do |a|
      y.yield plucker.pluck(a)
    end
  end
end

#modificationsObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/delta/base.rb', line 16

def modifications
  Enumerator.new do |y|
    set.intersection.each do |a, b|
      a_attributes = plucker.pluck(a)
      b_attributes = plucker.pluck(b)

      y.yield b_attributes unless a_attributes == b_attributes
    end
  end
end