Module: Hubbado::Trailblazer::Macro

Defined in:
lib/hubbado/trailblazer/macro/policy.rb,
lib/hubbado/trailblazer/macro/decorate_model.rb,
lib/hubbado/trailblazer/macro/deserialize_contract_params.rb

Defined Under Namespace

Modules: Policy

Class Method Summary collapse

Class Method Details

.DecorateModel(decorator, model: :model) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hubbado/trailblazer/macro/decorate_model.rb', line 4

def self.DecorateModel(decorator, model: :model)
  task = ->((ctx, flow_options), _) do
    unless ctx[model] && ctx[:current_user]
      return ::Trailblazer::Activity::Left, [ctx, flow_options]
    end

    ctx[model] = decorator.build(ctx[model], ctx[:current_user])

    [::Trailblazer::Activity::Right, [ctx, flow_options]]
  end

  { task: task, id: "Decorate" }
end

.DeserializeContractParams(key: nil) ⇒ Object

This is used to pre-populate a contract before validating it, so that form options can be built based on the contract values

For example, a contract, for a not yet saved assignment, might have timesheet approvers that depend on the client company ID in the contract



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hubbado/trailblazer/macro/deserialize_contract_params.rb', line 10

def self.DeserializeContractParams(key: nil)
  task = ->((ctx, flow_options), _) do
    ctx[:deserialized_params] = key || true

    params = key ? ctx[:params][key] : ctx[:params]

    return ::Trailblazer::Activity::Right, [ctx, flow_options] unless params

    ctx['contract.default'].deserialize(params)

    [::Trailblazer::Activity::Right, [ctx, flow_options]]
  end

  { task: task, id: "DeserializeContractParams" }
end

.Policy(policy_class, action, name: :default, model: :model) ⇒ Object



4
5
6
7
8
# File 'lib/hubbado/trailblazer/macro/policy.rb', line 4

def self.Policy(policy_class, action, name: :default, model: :model)
  ::Trailblazer::Macro::Policy.step(
    Policy.build(policy_class, action, model), name: name
  )
end