Class: ActiveRecord::ConnectionAdapters::TriggerDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::TriggerDefinition
- Defined in:
- lib/connection_adapters/trigger_definition.rb
Constant Summary collapse
- CLEAN =
0b0
- ROW =
0b00001
- BEFORE =
0b00010
- INSERT =
0b00100
- DELETE =
0b01000
- UPDATE =
0b10000
Instance Attribute Summary collapse
-
#binary_type ⇒ Object
Returns the value of attribute binary_type.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#procedure_name ⇒ Object
Returns the value of attribute procedure_name.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #before? ⇒ Boolean
-
#initialize(id, table, name = nil, binary_type = [], procedure_name = nil) ⇒ TriggerDefinition
constructor
A new instance of TriggerDefinition.
- #row? ⇒ Boolean
-
#to_rdl ⇒ Object
that’s to_r(uby)d(efinition)l(anguage).
-
#to_sql_create ⇒ Object
CREATE TRIGGER name { BEFORE | AFTER } { event [ OR … ] } ON table [ FOR [ EACH ] { ROW | STATEMENT } ] EXECUTE PROCEDURE funcname ( arguments ).
- #triggerized?(nam = nil) ⇒ Boolean
Constructor Details
#initialize(id, table, name = nil, binary_type = [], procedure_name = nil) ⇒ TriggerDefinition
Returns a new instance of TriggerDefinition.
13 14 15 16 17 18 19 |
# File 'lib/connection_adapters/trigger_definition.rb', line 13 def initialize(id, table, name=nil, binary_type=[], procedure_name=nil) @id = id @table = table self.binary_type = binary_type self.name = (name || triggerized_name) self.procedure_name = (procedure_name || name || triggerized_name) end |
Instance Attribute Details
#binary_type ⇒ Object
Returns the value of attribute binary_type.
12 13 14 |
# File 'lib/connection_adapters/trigger_definition.rb', line 12 def binary_type @binary_type end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/connection_adapters/trigger_definition.rb', line 11 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/connection_adapters/trigger_definition.rb', line 11 def name @name end |
#procedure_name ⇒ Object
Returns the value of attribute procedure_name.
11 12 13 |
# File 'lib/connection_adapters/trigger_definition.rb', line 11 def procedure_name @procedure_name end |
#table ⇒ Object
Returns the value of attribute table.
11 12 13 |
# File 'lib/connection_adapters/trigger_definition.rb', line 11 def table @table end |
Instance Method Details
#before? ⇒ Boolean
67 68 69 |
# File 'lib/connection_adapters/trigger_definition.rb', line 67 def before? calc(BEFORE) end |
#row? ⇒ Boolean
71 72 73 |
# File 'lib/connection_adapters/trigger_definition.rb', line 71 def row? calc(ROW) end |
#to_rdl ⇒ Object
that’s to_r(uby)d(efinition)l(anguage)
22 23 24 25 26 27 28 29 |
# File 'lib/connection_adapters/trigger_definition.rb', line 22 def to_rdl() " add_trigger #{table.to_sql_name}" << ", [" + events.join(", ") + "]" << ( before? ? ", :before => true" : "") << ( row? ? ", :row => true" : "") << (!triggerized? ? ", :name => #{ActiveSupport::Inflector.symbolize(name)}" : "") << (!triggerized?(procedure_name) ? ", :function => #{ActiveSupport::Inflector.symbolize(procedure_name)}" : "") end |
#to_sql_create ⇒ Object
CREATE TRIGGER name { BEFORE | AFTER } { event [ OR … ] }
ON table [ FOR [ EACH ] { ROW | STATEMENT } ]
EXECUTE PROCEDURE funcname ( arguments )
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/connection_adapters/trigger_definition.rb', line 43 def to_sql_create() result = "CREATE TRIGGER " << name.to_sql_name << (before? ? " BEFORE" : " AFTER") << " " << ( events.collect {|event| event.to_s.upcase.gsub(/^:/, '') }.join(" OR ") ) << " ON " << table.to_sql_name << " FOR EACH " << (row? ? "ROW" : "STATEMENT") << " EXECUTE PROCEDURE " << procedure_name.to_sql_name << "();" result end |
#triggerized?(nam = nil) ⇒ Boolean
62 63 64 65 |
# File 'lib/connection_adapters/trigger_definition.rb', line 62 def triggerized?(nam=nil) nam ||= self.name triggerized_name == nam end |