Class: Trigger
- Inherits:
-
Object
- Object
- Trigger
- Defined in:
- lib/polymorpheus/trigger.rb
Instance Attribute Summary collapse
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#collation_connection ⇒ Object
Returns the value of attribute collation_connection.
-
#created ⇒ Object
Returns the value of attribute created.
-
#db_collation ⇒ Object
Returns the value of attribute db_collation.
-
#definer ⇒ Object
Returns the value of attribute definer.
-
#event ⇒ Object
Returns the value of attribute event.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sql_mode ⇒ Object
Returns the value of attribute sql_mode.
-
#statement ⇒ Object
Returns the value of attribute statement.
-
#table ⇒ Object
Returns the value of attribute table.
-
#timing ⇒ Object
Returns the value of attribute timing.
Instance Method Summary collapse
- #columns ⇒ Object
-
#initialize(arr) ⇒ Trigger
constructor
A new instance of Trigger.
- #schema_statement ⇒ Object
Constructor Details
#initialize(arr) ⇒ Trigger
Returns a new instance of Trigger.
6 7 8 9 10 11 12 13 |
# File 'lib/polymorpheus/trigger.rb', line 6 def initialize(arr) raise ArgumentError unless arr.is_a?(Array) && arr.length == 11 [:name, :event, :table, :statement, :timing, :created, :sql_mode, :definer, :charset, :collation_connection, :db_collation]. each_with_index do |attr, ind| self.send("#{attr}=", arr[ind]) end end |
Instance Attribute Details
#charset ⇒ Object
Returns the value of attribute charset.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def charset @charset end |
#collation_connection ⇒ Object
Returns the value of attribute collation_connection.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def collation_connection @collation_connection end |
#created ⇒ Object
Returns the value of attribute created.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def created @created end |
#db_collation ⇒ Object
Returns the value of attribute db_collation.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def db_collation @db_collation end |
#definer ⇒ Object
Returns the value of attribute definer.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def definer @definer end |
#event ⇒ Object
Returns the value of attribute event.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def event @event end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def name @name end |
#sql_mode ⇒ Object
Returns the value of attribute sql_mode.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def sql_mode @sql_mode end |
#statement ⇒ Object
Returns the value of attribute statement.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def statement @statement end |
#table ⇒ Object
Returns the value of attribute table.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def table @table end |
#timing ⇒ Object
Returns the value of attribute timing.
3 4 5 |
# File 'lib/polymorpheus/trigger.rb', line 3 def timing @timing end |
Instance Method Details
#columns ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/polymorpheus/trigger.rb', line 15 def columns /IF\((.*)\) \<\> 1/.match(self.statement) do |match| match[1].split(' + ').collect do |submatch| /NEW\.([^ ]*)/.match(submatch)[1] end end end |
#schema_statement ⇒ Object
23 24 25 26 27 |
# File 'lib/polymorpheus/trigger.rb', line 23 def schema_statement # note that we don't need to worry about unique indices or foreign keys # because separate schema statements will be generated for them " add_polymorphic_triggers(:#{table}, #{columns.to_s})" end |