Class: PgSqlTriggers::DSL::TriggerDefinition
- Inherits:
-
Object
- Object
- PgSqlTriggers::DSL::TriggerDefinition
- Defined in:
- lib/pg_sql_triggers/dsl/trigger_definition.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#constraint_trigger ⇒ Object
Intentionally not named ‘constraint_trigger?` — matches registry column and JSON key.
-
#deferrable ⇒ Object
Returns the value of attribute deferrable.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#environments ⇒ Object
Returns the value of attribute environments.
-
#events ⇒ Object
Returns the value of attribute events.
-
#for_each ⇒ Object
readonly
Returns the value of attribute for_each.
-
#function_name ⇒ Object
Returns the value of attribute function_name.
-
#initially ⇒ Object
Returns the value of attribute initially.
-
#name ⇒ Object
Returns the value of attribute name.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
-
#timing ⇒ Object
Returns the value of attribute timing.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #constraint_trigger! ⇒ Object
-
#depends_on(*names) ⇒ Object
Declares that this trigger must run after the named trigger(s) on the same table.
- #depends_on_names ⇒ Object
- #for_each_row ⇒ Object
- #for_each_statement ⇒ Object
- #function(function_name) ⇒ Object
- #function_body ⇒ Object
-
#initialize(name) ⇒ TriggerDefinition
constructor
A new instance of TriggerDefinition.
- #on(*events) ⇒ Object
- #on_update_of(*cols) ⇒ Object
- #table(table_name) ⇒ Object
- #to_h ⇒ Object
- #when_condition(condition_sql) ⇒ Object
- #when_env(*environments) ⇒ Object
Constructor Details
#initialize(name) ⇒ TriggerDefinition
Returns a new instance of TriggerDefinition.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 10 def initialize(name) @name = name @events = [] @version = 1 @enabled = true @environments = [] @condition = nil @timing = "before" @for_each = "row" @columns = nil @constraint_trigger = false @deferrable = nil @initially = nil @depends_on = [] end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def columns @columns end |
#condition ⇒ Object
Returns the value of attribute condition.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def condition @condition end |
#constraint_trigger ⇒ Object
Intentionally not named ‘constraint_trigger?` — matches registry column and JSON key. The setter always casts to a boolean, and the initial value is `false`, so this returns the stored value directly without coercion.
29 30 31 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 29 def constraint_trigger @constraint_trigger end |
#deferrable ⇒ Object
Returns the value of attribute deferrable.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def deferrable @deferrable end |
#enabled ⇒ Object
Returns the value of attribute enabled.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def enabled @enabled end |
#environments ⇒ Object
Returns the value of attribute environments.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def environments @environments end |
#events ⇒ Object
Returns the value of attribute events.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def events @events end |
#for_each ⇒ Object (readonly)
Returns the value of attribute for_each.
8 9 10 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 8 def for_each @for_each end |
#function_name ⇒ Object
Returns the value of attribute function_name.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def function_name @function_name end |
#initially ⇒ Object
Returns the value of attribute initially.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def initially @initially end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def name @name end |
#table_name ⇒ Object
Returns the value of attribute table_name.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def table_name @table_name end |
#timing ⇒ Object
Returns the value of attribute timing.
8 9 10 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 8 def timing @timing end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 6 def version @version end |
Instance Method Details
#constraint_trigger! ⇒ Object
58 59 60 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 58 def constraint_trigger! self.constraint_trigger = true end |
#depends_on(*names) ⇒ Object
Declares that this trigger must run after the named trigger(s) on the same table. PostgreSQL executes same-kind triggers in alphabetical order by name; use naming or validate with Registry.validate! / rake trigger:validate_order.
84 85 86 87 88 89 90 91 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 84 def depends_on(*names) names.flatten.compact.each do |entry| label = entry.to_s.strip next if label.empty? @depends_on << label unless @depends_on.include?(label) end end |
#depends_on_names ⇒ Object
93 94 95 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 93 def depends_on_names @depends_on.dup end |
#for_each_row ⇒ Object
62 63 64 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 62 def for_each_row @for_each = "row" end |
#for_each_statement ⇒ Object
66 67 68 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 66 def for_each_statement @for_each = "statement" end |
#function(function_name) ⇒ Object
50 51 52 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 50 def function(function_name) @function_name = function_name end |
#function_body ⇒ Object
97 98 99 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 97 def function_body nil # DSL definitions don't include function_body directly end |
#on(*events) ⇒ Object
40 41 42 43 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 40 def on(*events) @events = events.map(&:to_s) @columns = nil end |
#on_update_of(*cols) ⇒ Object
45 46 47 48 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 45 def on_update_of(*cols) @events = ["update"] @columns = cols.map(&:to_s) end |
#table(table_name) ⇒ Object
36 37 38 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 36 def table(table_name) @table_name = table_name end |
#to_h ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 101 def to_h { name: @name, table_name: @table_name, events: @events, function_name: @function_name, version: @version, enabled: @enabled, environments: @environments, condition: @condition, timing: @timing, for_each: @for_each, columns: @columns, constraint_trigger: @constraint_trigger == true, deferrable: @deferrable&.to_s, initially: @initially&.to_s, depends_on: @depends_on.dup } end |
#when_condition(condition_sql) ⇒ Object
77 78 79 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 77 def when_condition(condition_sql) @condition = condition_sql end |
#when_env(*environments) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/pg_sql_triggers/dsl/trigger_definition.rb', line 70 def when_env(*environments) warn "[DEPRECATION] `when_env` is deprecated and will be removed in a future version. " \ "Environment-specific trigger behavior causes schema drift between environments. " \ "Use application-level configuration instead." @environments = environments.map(&:to_s) end |