Module: DynamicMigrations::Postgres::Server::Database::Schema::Table::Triggers
- Defined in:
- lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb
Overview
This module has all the tables methods for working with triggers
Defined Under Namespace
Classes: TriggerAlreadyExistsError, TriggerDoesNotExistError
Instance Method Summary collapse
-
#add_trigger(name, action_timing:, event_manipulation:, parameters:, action_orientation:, function:, action_order: nil, action_condition: nil, action_reference_old_table: nil, action_reference_new_table: nil, description: nil, template: nil) ⇒ Object
adds a new trigger to this table, and returns it.
-
#has_trigger?(name) ⇒ Boolean
returns true if this table has a trigger with the provided name, otherwise false.
-
#trigger(name) ⇒ Object
returns the trigger object for the provided trigger name, and raises an error if the trigger does not exist.
-
#triggers ⇒ Object
returns an array of this tables triggers.
- #triggers_hash ⇒ Object
Instance Method Details
#add_trigger(name, action_timing:, event_manipulation:, parameters:, action_orientation:, function:, action_order: nil, action_condition: nil, action_reference_old_table: nil, action_reference_new_table: nil, description: nil, template: nil) ⇒ Object
adds a new trigger to this table, and returns it
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb', line 41 def add_trigger name, action_timing:, event_manipulation:, parameters:, action_orientation:, function:, action_order: nil, action_condition: nil, action_reference_old_table: nil, action_reference_new_table: nil, description: nil, template: nil if has_trigger? name raise(TriggerAlreadyExistsError, "Trigger #{name} already exists") end included_target = self if included_target.is_a? Table new_trigger = @triggers[name] = Trigger.new source, included_target, name, action_timing: action_timing, event_manipulation: event_manipulation, action_order: action_order, parameters: parameters, action_orientation: action_orientation, function: function, action_condition: action_condition, action_reference_old_table: action_reference_old_table, action_reference_new_table: action_reference_new_table, description: description, template: template else raise ModuleIncludedIntoUnexpectedTargetError, included_target end # sort the hash so that the triggers are in alphabetical order by name sorted_triggers = {} @triggers.keys.sort.each do |name| sorted_triggers[name] = @triggers[name] end @triggers = sorted_triggers # return the new trigger new_trigger end |
#has_trigger?(name) ⇒ Boolean
returns true if this table has a trigger with the provided name, otherwise false
26 27 28 29 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb', line 26 def has_trigger? name raise Trigger::InvalidNameError, name unless name.is_a? Symbol @triggers.key? name end |
#trigger(name) ⇒ Object
returns the trigger object for the provided trigger name, and raises an error if the trigger does not exist
19 20 21 22 23 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb', line 19 def trigger name raise Trigger::InvalidNameError, name unless name.is_a? Symbol raise TriggerDoesNotExistError unless has_trigger? name @triggers[name] end |
#triggers ⇒ Object
returns an array of this tables triggers
32 33 34 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb', line 32 def triggers @triggers.values end |
#triggers_hash ⇒ Object
36 37 38 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/triggers.rb', line 36 def triggers_hash @triggers end |