Class: ActiveRecord::Ingress::Base

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/active_record/ingress/base.rb

Defined Under Namespace

Modules: Callbacks

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, params = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/active_record/ingress/base.rb', line 7

def initialize(record, params = {})
  @record, @params = record, params
end

Instance Attribute Details

#perform_with_paramsObject (readonly)

Returns the value of attribute perform_with_params.



5
6
7
# File 'lib/active_record/ingress/base.rb', line 5

def perform_with_params
  @perform_with_params
end

Class Method Details

.inherited(klass) ⇒ Object



11
12
13
14
15
# File 'lib/active_record/ingress/base.rb', line 11

def self.inherited(klass)
  if alias_name = klass.module_parent_name.chomp("::Ingressed").underscore.presence
    alias_method alias_name, :record
  end
end

.method_added(name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/active_record/ingress/base.rb', line 17

def self.method_added(name)
  if name == :perform
    if instance_method(:perform).arity.nonzero?
      @perform_with_params = ->(params) { perform(**params.to_h) }
    else
      @perform_with_params = ->(params) { perform }
    end
  end
end

.runObject



27
28
29
# File 'lib/active_record/ingress/base.rb', line 27

def self.run(...)
  new(...).run
end

Instance Method Details

#runObject



31
32
33
34
35
# File 'lib/active_record/ingress/base.rb', line 31

def run
  run_callbacks :perform do
    instance_exec(params, &self.class.perform_with_params)
  end
end