Class: Macros::CurrentUser::Set

Inherits:
Base
  • Object
show all
Defined in:
lib/macros/current_user/set.rb

Overview

Sets the current_user in the context.

Instance Method Summary collapse

Methods inherited from Base

register

Constructor Details

#initialize(key: :model) ⇒ Macro::CurrentUser::Set

Returns step macro instance.



11
12
13
# File 'lib/macros/current_user/set.rb', line 11

def initialize(key: :model)
  @key = key
end

Instance Method Details

#call(ctx) ⇒ Object

Sets the current user in the context

Parameters:

  • ctx (Trailblazer::Skill)

    tbl context hash



17
18
19
20
21
22
# File 'lib/macros/current_user/set.rb', line 17

def call(ctx, **)
  return false unless ctx[@key]
  return false unless VALID_CURRENT_USER_CLASS_NAMES.include? ctx[@key].class.name.demodulize

  ctx[:current_user] = ctx[@key]
end