Sha256: 6ccaac6e18ef99046e621076a538716e81465291a26139b25adb6917eccbd858

Contents?: true

Size: 1008 Bytes

Versions: 2

Compression:

Stored size: 1008 Bytes

Contents

module LucidAuthorization
  module Mixin
    def authorized?(target_class, target_method = nil, props = nil)
      begin
        class_name = self.class.name
        class_name = class_name.split('>::').last if class_name.start_with?('#<')
        policy_class = Isomorfeus.cached_policy_class("#{class_name}Policy")
      rescue ::NameError
        policy_class = nil
      end
      return false unless policy_class
      policy_class.new(self).authorized?(target_class, target_method, props)
    end

    def authorized!(target_class, target_method = nil, props = nil)
      class_name = self.class.name
      class_name = class_name.split('>::').last if class_name.start_with?('#<')
      policy_class = Isomorfeus.cached_policy_class("#{class_name}Policy")
      Isomorfeus.raise_error(error_class: LucidPolicy::Exception, message: "#{self}: policy class #{class_name}Policy not found!") unless policy_class
      policy_class.new(self).authorized!(target_class, target_method, props)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
isomorfeus-policy-1.0.0.zeta20 lib/isomorfeus_policy/lucid_authorization/mixin.rb
isomorfeus-policy-1.0.0.zeta19 lib/isomorfeus_policy/lucid_authorization/mixin.rb