module Trailblazer::Rails::Controller
Public Instance Methods
run_v21(operation, *dependencies) { |result| ... }
click to toggle source
# File lib/trailblazer/rails/controller.rb, line 3 def run_v21(operation, *dependencies) result = if Rails.application.config.trailblazer.enable_tracing _run_operation_v21(operation, :trace, *dependencies).tap { |r| _operation_trace(r) } else _run_operation_v21(operation, :call, *dependencies) end _assign_trb_ivars(result) yield(result) if result.success? && block_given? @_result = result end
Also aliased as: run
Private Instance Methods
_assign_trb_ivars(result)
click to toggle source
# File lib/trailblazer/rails/controller.rb, line 49 def _assign_trb_ivars(result) @model = result[:model] @form = _wrap_with_trb_form(result["contract.default"], @model.class) end
_operation_trace(result)
click to toggle source
# File lib/trailblazer/rails/controller.rb, line 45 def _operation_trace(result) puts result.wtf? end
_run_operation_v21(operation, call_method, *dependencies)
click to toggle source
# File lib/trailblazer/rails/controller.rb, line 38 def _run_operation_v21(operation, call_method, *dependencies) operation.send( call_method, {params: _run_params(self.params)}.merge(*_run_runtime_options(*dependencies)) # rubocop:disable Style/RedundantSelf ) end
_run_options(ctx)
click to toggle source
Override this to inject dependencies such as “current_user” into the runtime options.
# File lib/trailblazer/rails/controller.rb, line 34 def _run_options(ctx) ctx end
_run_params(params)
click to toggle source
Override to tweak params. Not recommended. Use a deserializer instead.
# File lib/trailblazer/rails/controller.rb, line 23 def _run_params(params) params end
_run_runtime_options(ctx = {}, *dependencies)
click to toggle source
This is where we can inject Dry.RB containers and the like via dependencies.
# File lib/trailblazer/rails/controller.rb, line 28 def _run_runtime_options(ctx = {}, *dependencies) [_run_options(ctx), *dependencies] end
_wrap_with_trb_form(form, model)
click to toggle source
# File lib/trailblazer/rails/controller.rb, line 54 def _wrap_with_trb_form(form, model) Trailblazer::Rails::Form.new(form, model) end