Sha256: 5bd3a5f17ffed668b84bcfa35eb0df79db8ba46d99647a68c7b79db02bf0f25f

Contents?: true

Size: 1020 Bytes

Versions: 6

Compression:

Stored size: 1020 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 = nil)
    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 = nil)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
isomorfeus-policy-1.0.0.zeta18 lib/isomorfeus_policy/lucid_authorization/mixin.rb
isomorfeus-policy-1.0.0.zeta17 lib/isomorfeus_policy/lucid_authorization/mixin.rb
isomorfeus-policy-1.0.0.zeta16 lib/isomorfeus_policy/lucid_authorization/mixin.rb
isomorfeus-policy-1.0.0.zeta15 lib/isomorfeus_policy/lucid_authorization/mixin.rb
isomorfeus-policy-1.0.0.zeta14 lib/isomorfeus_policy/lucid_authorization/mixin.rb
isomorfeus-policy-1.0.0.zeta13 lib/isomorfeus_policy/lucid_authorization/mixin.rb