Class: ActiveRecord::ConnectionAdapters::PostgreSQLTriggerDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLTriggerDefinition
- Defined in:
- lib/active_record/postgresql_extensions/triggers.rb
Overview
Creates a PostgreSQL trigger definition. This class isn’t really meant to be used directly. You’d be better off sticking to PostgreSQLAdapter#create_trigger. Honestly.
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#called ⇒ Object
Returns the value of attribute called.
-
#events ⇒ Object
Returns the value of attribute events.
-
#function ⇒ Object
Returns the value of attribute function.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
-
#initialize(base, name, called, events, table, function, options = {}) ⇒ PostgreSQLTriggerDefinition
constructor
:nodoc:.
-
#to_sql ⇒ Object
(also: #to_s)
:nodoc:.
Constructor Details
#initialize(base, name, called, events, table, function, options = {}) ⇒ PostgreSQLTriggerDefinition
:nodoc:
116 117 118 119 120 121 122 123 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 116 def initialize(base, name, called, events, table, function, = {}) #:nodoc: assert_valid_called(called) assert_valid_events(events) assert_valid_for_each([:for_each]) @base, @name, @events, @called, @table, @function, @options = base, name, events, called, table, function, end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
114 115 116 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 114 def base @base end |
#called ⇒ Object
Returns the value of attribute called.
114 115 116 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 114 def called @called end |
#events ⇒ Object
Returns the value of attribute events.
114 115 116 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 114 def events @events end |
#function ⇒ Object
Returns the value of attribute function.
114 115 116 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 114 def function @function end |
#name ⇒ Object
Returns the value of attribute name.
114 115 116 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 114 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
114 115 116 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 114 def @options end |
#table ⇒ Object
Returns the value of attribute table.
114 115 116 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 114 def table @table end |
Instance Method Details
#to_sql ⇒ Object Also known as: to_s
:nodoc:
125 126 127 128 129 130 131 132 133 |
# File 'lib/active_record/postgresql_extensions/triggers.rb', line 125 def to_sql #:nodoc: sql = "CREATE TRIGGER #{base.quote_generic(name)} #{called.to_s.upcase} " sql << Array.wrap(events).collect { |e| e.to_s.upcase }.join(' OR ') sql << " OF " << Array.wrap([:of]).collect { |o| base.quote_generic(o) }.join(', ') if [:of].present? sql << " ON #{base.quote_table_name(table)}" sql << " FOR EACH #{[:for_each].to_s.upcase}" if [:for_each] sql << " EXECUTE PROCEDURE #{base.quote_function(function)}(#{[:args]})" "#{sql};" end |