Skip to content
Vladislav Trotsenko edited this page Sep 27, 2019 · 2 revisions

Synopsis

Provides to assign into context value from other context/context chains.

Examples of usage

Assign data to context from other context chains

class SomeOperation < ApplicationOperation
  # ctx[:some_attribute] = ctx['contract.default'].some_attribute
  step Macro::Assign(to: :some_attribute, path: %w[contract.default some_attribute])
  # ctx[:model] = ctx[:current_account].user
  step Macro::Assign(to: :model, path: %i[current_account user])
end

Safe assign from context chains

class SomeOperation < ApplicationOperation
  step Macro::Assign(
    to: :model,
    path: %i[current_account not_existing_method],
    try: true
  ) # ctx[:model] => nil
end

Directly assign value to context

class SomeOperation < ApplicationOperation
  # ctx[:some_attribute] = :some_value
  step Macro::Assign(to: :some_attribute, value: :some_value)
end
Clone this wiki locally