Class: PgTrigger::Plan::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_trigger/plan.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected, existing) ⇒ Builder

Returns a new instance of Builder.



11
12
13
14
# File 'lib/pg_trigger/plan.rb', line 11

def initialize(expected, existing)
  @expected = expected
  @existing = existing
end

Instance Method Details

#resultObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pg_trigger/plan.rb', line 16

def result
  plan = Plan.new

  # Find new or updated triggers
  @expected.each do |t|
    e = @existing.find { |_t| _t.name == t.name }
    if e
      plan.update_trigger(e, t) unless t.same?(e)
    else
      plan.add_trigger(t)
    end
  end

  # Find removed triggers
  @existing.each do |e|
    next if @expected.any? { |t| t.name == e.name }
    plan.drop_trigger(e)
  end

  plan
end