Class: Hayfork::Triggers
- Inherits:
-
Object
- Object
- Hayfork::Triggers
- Defined in:
- lib/hayfork/triggers.rb
Instance Attribute Summary collapse
-
#haystack ⇒ Object
readonly
Returns the value of attribute haystack.
Instance Method Summary collapse
- #<<(trigger) ⇒ Object
- #create ⇒ Object
- #drop ⇒ Object
-
#initialize(haystack) ⇒ Triggers
constructor
A new instance of Triggers.
- #rebuild ⇒ Object
- #replace ⇒ Object
- #truncate ⇒ Object
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
#haystack ⇒ Object (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 |
#create ⇒ Object
14 15 16 |
# File 'lib/hayfork/triggers.rb', line 14 def create _triggers.map { |args| psql_create_triggers_for(*args) }.join end |
#drop ⇒ Object
18 19 20 |
# File 'lib/hayfork/triggers.rb', line 18 def drop _triggers.map { |model, _, | psql_drop_triggers_for(model, ) }.join end |
#rebuild ⇒ Object
30 31 32 |
# File 'lib/hayfork/triggers.rb', line 30 def rebuild ([truncate] + _triggers.map { |args| psql_inserts_for(*args) }).join end |
#replace ⇒ Object
22 23 24 |
# File 'lib/hayfork/triggers.rb', line 22 def replace [drop, create].join end |
#truncate ⇒ Object
26 27 28 |
# File 'lib/hayfork/triggers.rb', line 26 def truncate "TRUNCATE #{haystack.table_name};\n" end |