Sha256: 5e0cf81374cd337958fa30d7875b53990cb88af30ba64ff4876cddb359b0bcaf

Contents?: true

Size: 834 Bytes

Versions: 8

Compression:

Stored size: 834 Bytes

Contents

require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/string/inflections'
require 'pundit'

module CrewdPolicies
	# optional
	class BasePolicy
		include Policy

		attr_reader :identity, :record

		def initialize(identity, record)
	     @identity = identity
	     @record = record
		end

		def model_class
	    @policy_class ||= self.class.name.sub(/Policy$/,'').safe_constantize  # record ? record.class
	   end

		def scope
	     Pundit.policy_scope!(identity, model_class)
	   end

		class Scope
	     attr_reader :identity, :scope

	    def initialize(identity, scope)
	      @identity = identity
	      @scope = scope
	    end

	    def model_class
	      @policy_class ||= (self.class.name.sub(/Policy::Scope$/,'').safe_constantize or @scope)
	    end

			def resolve
				scope
			end
		end
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
crewd_policies-0.4.0 lib/crewd_policies/base_policy.rb
crewd_policies-0.3.3 lib/crewd_policies/base_policy.rb
crewd_policies-0.3.2 lib/crewd_policies/base_policy.rb
crewd_policies-0.3.1 lib/crewd_policies/base_policy.rb
crewd_policies-0.3.0 lib/crewd_policies/base_policy.rb
crewd_policies-0.2.2 lib/crewd_policies/base_policy.rb
crewd_policies-0.2.1 lib/crewd_policies/base_policy.rb
crewd_policies-0.2.0 lib/crewd_policies/base_policy.rb