Sha256: 1df608f8468218cc40cf87f4e879a5aa164f4d1018f80f383f5eb679505b83bf

Contents?: true

Size: 662 Bytes

Versions: 7

Compression:

Stored size: 662 Bytes

Contents

# frozen_string_literal: true

module Macros
  class CurrentUser
    VALID_CURRENT_USER_CLASS_NAMES = %w[User Admin].freeze

    # Sets the current_user in the context.
    #
    class Set < Macros::Base
      # @return [Macro::CurrentUser::Set] step macro instance
      def initialize(key: :model)
        @key = key
      end

      # Sets the current user in the context
      # @param ctx [Trailblazer::Skill] tbl context hash
      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
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ff-tbl-macros-2.0.2 lib/macros/current_user/set.rb
ff-tbl-macros-2.0.1 lib/macros/current_user/set.rb
ff-tbl-macros-2.0.0 lib/macros/current_user/set.rb
ff-tbl-macros-1.0.2 lib/macros/current_user/set.rb
ff-tbl-macros-1.0.1 lib/macros/current_user/set.rb
ff-tbl-macros-1.0.0 lib/macros/current_user/set.rb
ff-tbl-macros-0.1.8 lib/macros/current_user/set.rb