Class: Hayfork::Triggers

Inherits:
Object
  • Object
show all
Defined in:
lib/hayfork/triggers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(haystack) ⇒ Triggers

Returns a new instance of Triggers.



5
6
7
8
# File 'lib/hayfork/triggers.rb', line 5

def initialize(haystack)
  @haystack = haystack
  @_triggers = []
end

Instance Attribute Details

#haystackObject (readonly)

Returns the value of attribute haystack.



3
4
5
# File 'lib/hayfork/triggers.rb', line 3

def haystack
  @haystack
end

Instance Method Details

#<<(trigger) ⇒ Object



10
11
12
# File 'lib/hayfork/triggers.rb', line 10

def <<(trigger)
  _triggers << trigger
end

#createObject



14
15
16
# File 'lib/hayfork/triggers.rb', line 14

def create
  _triggers.map { |args| psql_create_triggers_for(*args) }.join
end

#dropObject



18
19
20
# File 'lib/hayfork/triggers.rb', line 18

def drop
  _triggers.map { |model, _, options| psql_drop_triggers_for(model, options) }.join
end

#rebuildObject



30
31
32
# File 'lib/hayfork/triggers.rb', line 30

def rebuild
  ([truncate] + _triggers.map { |args| psql_inserts_for(*args) }).join
end

#replaceObject



22
23
24
# File 'lib/hayfork/triggers.rb', line 22

def replace
  [drop, create].join
end

#truncateObject



26
27
28
# File 'lib/hayfork/triggers.rb', line 26

def truncate
  "TRUNCATE #{haystack.table_name};\n"
end