Class: Polymorpheus::Trigger
- Inherits:
-
Object
- Object
- Polymorpheus::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.
7 8 9 10 11 12 13 14 |
# File 'lib/polymorpheus/trigger.rb', line 7 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.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def charset @charset end |
#collation_connection ⇒ Object
Returns the value of attribute collation_connection.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def collation_connection @collation_connection end |
#created ⇒ Object
Returns the value of attribute created.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def created @created end |
#db_collation ⇒ Object
Returns the value of attribute db_collation.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def db_collation @db_collation end |
#definer ⇒ Object
Returns the value of attribute definer.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def definer @definer end |
#event ⇒ Object
Returns the value of attribute event.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def event @event end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def name @name end |
#sql_mode ⇒ Object
Returns the value of attribute sql_mode.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def sql_mode @sql_mode end |
#statement ⇒ Object
Returns the value of attribute statement.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def statement @statement end |
#table ⇒ Object
Returns the value of attribute table.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def table @table end |
#timing ⇒ Object
Returns the value of attribute timing.
4 5 6 |
# File 'lib/polymorpheus/trigger.rb', line 4 def timing @timing end |
Instance Method Details
#columns ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/polymorpheus/trigger.rb', line 16 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
24 25 26 27 28 |
# File 'lib/polymorpheus/trigger.rb', line 24 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 |