Sha256: 3e56c84bc119ce158b945f50059fd53ce1e630ccd18f9f9e9fb5496497dc3b1d

Contents?: true

Size: 960 Bytes

Versions: 2

Compression:

Stored size: 960 Bytes

Contents

module LucidAuthorization
  module Mixin
    def authorized?(target_class, target_method = nil, *props)
      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)
      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")
      raise LucidPolicy::Exception, "#{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.zeta12 lib/isomorfeus_policy/lucid_authorization/mixin.rb
isomorfeus-policy-1.0.0.zeta11 lib/isomorfeus_policy/lucid_authorization/mixin.rb