Class: ActiveRecord::ConnectionAdapters::PostgreSQLEventTriggerDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLEventTriggerDefinition
- Defined in:
- lib/active_record/postgresql_extensions/event_triggers.rb
Overview
Creates a PostgreSQL event trigger definition. This class isn’t really meant to be used directly. You’d be better off sticking to PostgreSQLAdapter#create_event_trigger. Honestly.
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#event ⇒ Object
Returns the value of attribute event.
-
#function ⇒ Object
Returns the value of attribute function.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(base, name, event, function, options = {}) ⇒ PostgreSQLEventTriggerDefinition
constructor
:nodoc:.
-
#to_sql ⇒ Object
(also: #to_s)
:nodoc:.
Constructor Details
#initialize(base, name, event, function, options = {}) ⇒ PostgreSQLEventTriggerDefinition
:nodoc:
86 87 88 89 90 91 |
# File 'lib/active_record/postgresql_extensions/event_triggers.rb', line 86 def initialize(base, name, event, function, = {}) #:nodoc: assert_valid_event_name(event) @base, @name, @event, @function, @options = base, name, event, function, end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
84 85 86 |
# File 'lib/active_record/postgresql_extensions/event_triggers.rb', line 84 def base @base end |
#event ⇒ Object
Returns the value of attribute event.
84 85 86 |
# File 'lib/active_record/postgresql_extensions/event_triggers.rb', line 84 def event @event end |
#function ⇒ Object
Returns the value of attribute function.
84 85 86 |
# File 'lib/active_record/postgresql_extensions/event_triggers.rb', line 84 def function @function end |
#name ⇒ Object
Returns the value of attribute name.
84 85 86 |
# File 'lib/active_record/postgresql_extensions/event_triggers.rb', line 84 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
84 85 86 |
# File 'lib/active_record/postgresql_extensions/event_triggers.rb', line 84 def @options end |
Instance Method Details
#to_sql ⇒ Object Also known as: to_s
:nodoc:
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/active_record/postgresql_extensions/event_triggers.rb', line 93 def to_sql #:nodoc: sql = "CREATE EVENT TRIGGER #{base.quote_generic(name)} ON #{base.quote_generic(event)}" if [:when].present? sql << "\n WHEN " sql << [:when].inject([]) { |memo, (k, v)| memo.tap { values = Array.wrap(v).collect { |value| base.quote(value) }.join(', ') memo << "#{base.quote_generic(k)} IN (#{values})" } }.join("\n AND ") sql << "\n " end sql << " EXECUTE PROCEDURE #{base.quote_function(function)}()" "#{sql};" end |