Class: Macros::Model::Persist

Inherits:
Base
  • Object
show all
Defined in:
lib/macros/model/persist.rb

Overview

Persist object from the context

Examples:

step Macros::Model::Persist(ctx_key: :weekly_plan_editing)

Instance Method Summary collapse

Methods inherited from Base

register

Constructor Details

#initialize(ctx_key: :model, method: :save!) ⇒ Persist

Returns a new instance of Persist.



9
10
11
12
# File 'lib/macros/model/persist.rb', line 9

def initialize(ctx_key: :model, method: :save!)
  @ctx_key = ctx_key
  @method = method
end

Instance Method Details

#call(ctx) ⇒ Object



14
15
16
17
18
# File 'lib/macros/model/persist.rb', line 14

def call(ctx, **)
  return false unless ctx[@ctx_key]

  ctx[@ctx_key].public_send(@method)
end