Sha256: 0e436a0dc1319dbbcd8c534bb9d3af8e939ff84baecf18cc2c63a242ce20f2ee

Contents?: true

Size: 774 Bytes

Versions: 1

Compression:

Stored size: 774 Bytes

Contents

# frozen_string_literal: true

module Logux
  class PolicyCaller
    attr_reader :action, :meta

    delegate :logger, :configuration, to: :Logux

    def initialize(action:, meta:)
      @action = action
      @meta = meta
    end

    def call!
      logger.debug('Searching policy for Logux action:' \
                   " #{action}, meta: #{meta}")
      policy.public_send("#{action.action_type}?")
    rescue Logux::UnknownActionError, Logux::UnknownChannelError => e
      raise e if configuration.verify_authorized

      logger.warn(e)
    end

    private

    def class_finder
      @class_finder ||= Logux::ClassFinder.new(action: action, meta: meta)
    end

    def policy
      class_finder.find_policy_class.new(action: action, meta: meta)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logux_rails-0.1.0 lib/logux/policy_caller.rb