module PGTrunk::Operation::Callbacks
@private Enable to fulfill/generate missed attributes using the ‘after_initialize` callback.
The callback is invoked after the end of the normal initialization and applying a block with explicit settings.
Public Class Methods
new(*, **, &block)
click to toggle source
Calls superclass method
# File lib/pg_trunk/core/operation/callbacks.rb, line 31 def initialize(*, **, &block) # Explicitly assign all attributes from params/options. super # Explicitly assign attributes using a block. block&.call(self) # Apply +callback+ at the very end after all explicit assignments. self.class.callbacks.each { |callback| instance_exec(&callback) } end
Public Instance Methods
after_initialize(&block)
click to toggle source
Get or set the callback
# File lib/pg_trunk/core/operation/callbacks.rb, line 19 def after_initialize(&block) callbacks << block if block end
callbacks()
click to toggle source
# File lib/pg_trunk/core/operation/callbacks.rb, line 14 def callbacks @callbacks ||= [] end
inherited(klass)
click to toggle source
Calls superclass method
# File lib/pg_trunk/core/operation/callbacks.rb, line 25 def inherited(klass) klass.instance_variable_set(:@callbacks, callbacks.dup) super end