Class: Permits::Policy::Base
- Inherits:
-
Object
- Object
- Permits::Policy::Base
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Validations
- Defined in:
- lib/permits/policy/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authorized?(action) ⇒ Boolean
- #has_action_permissions?(action, for_resource: resource, for_resource_type: nil, for_resource_id: nil) ⇒ Boolean
Class Method Details
.authorize!(owner, resource, action) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/permits/policy/base.rb', line 14 def self.(owner, resource, action) policy = new(owner: owner, resource: resource) if policy.(action) true else raise ::Permits::Policy::UnauthorizedError end end |
.authorized?(owner, resource, action) ⇒ Boolean
23 24 25 26 |
# File 'lib/permits/policy/base.rb', line 23 def self.(owner, resource, action) policy = new(owner: owner, resource: resource) policy.(action) end |
Instance Method Details
#authorized?(action) ⇒ Boolean
28 29 30 31 32 33 34 35 36 |
# File 'lib/permits/policy/base.rb', line 28 def (action) return false unless valid? if respond_to?("#{action}?") send("#{action}?") else (action) end end |
#has_action_permissions?(action, for_resource: resource, for_resource_type: nil, for_resource_id: nil) ⇒ Boolean
38 39 40 41 42 43 44 45 46 |
# File 'lib/permits/policy/base.rb', line 38 def (action, for_resource: resource, for_resource_type: nil, for_resource_id: nil) return false unless .respond_to?("permits_#{action}") if for_resource_type && for_resource_id .send("permits_#{action}").where(resource_type: for_resource_type, resource_id: for_resource_id).exists? else .send("permits_#{action}").where(resource: for_resource).exists? end end |