Class: Macros::Model::Build
Instance Method Summary collapse
-
#call(ctx) ⇒ Object
Sets the model in the context.
-
#initialize(from:, respond_to: nil) ⇒ Macros::Model::Build
constructor
Step macro instance.
Methods inherited from Base
Constructor Details
#initialize(from:, respond_to: nil) ⇒ Macros::Model::Build
Returns step macro instance.
14 15 16 17 |
# File 'lib/macros/model/build.rb', line 14 def initialize(from:, respond_to: nil) @from = from @respond_to = respond_to end |
Instance Method Details
#call(ctx) ⇒ Object
Sets the model in the context
21 22 23 24 25 26 27 28 29 |
# File 'lib/macros/model/build.rb', line 21 def call(ctx, **) scope = ctx[@from] return false unless scope klass = scope.to_s.classify.constantize return false if @respond_to && !klass.new.respond_to?(@respond_to) ctx[:model] = klass.new end |