Module: DbAgile::Core::Schema::Computations::Minus

Included in:
DbAgile::Core::Schema::Computations
Defined in:
lib/dbagile/core/schema/computations/minus.rb

Instance Method Summary collapse

Instance Method Details

#minus(left, right, builder) ⇒ Object

Computes set difference between schemas.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dbagile/core/schema/computations/minus.rb', line 8

def minus(left, right, builder)
  unless left.class == right.class
    raise ArgumentError, "#{left.class} != #{right.class}"
  end
  unless left.composite?
    raise ArgumentError, "Minus called on a part object!"
  end
  
  result = builder.send(left.builder_handler, *left.builder_args){|builder_object|
    left.part_keys.each{|name|
      left_sub, right_sub = left[name], right[name]
      if right_sub.nil?
        # missing in right
        builder_object[name] = left_sub.dup
      elsif left_sub.composite?
        # present in right, possibly the same
        minus(left_sub, right_sub, builder)
      elsif not(left_sub.look_same_as?(right_sub))
        # present in right, conflicting
        builder_object[name] = left_sub.dup
      else
        # present in right, same 
        # (following line otherwise, not counted by rcov)
        1
      end
    }
  }
  
  result
end