Class: ResourcePolicy::Policy::AttributesPolicy::AttributePolicy
- Inherits:
-
Object
- Object
- ResourcePolicy::Policy::AttributesPolicy::AttributePolicy
- Defined in:
- lib/resource_policy/policy/attributes_policy/attribute_policy.rb
Overview
Stores information about access level of single attribute.
Instance Method Summary collapse
- #allowed_to?(access_level) ⇒ Boolean
-
#initialize(attribute_config, policy:) ⇒ AttributePolicy
constructor
A new instance of AttributePolicy.
- #name ⇒ Object
- #readable? ⇒ Boolean
- #writable? ⇒ Boolean
Constructor Details
#initialize(attribute_config, policy:) ⇒ AttributePolicy
Returns a new instance of AttributePolicy.
10 11 12 13 |
# File 'lib/resource_policy/policy/attributes_policy/attribute_policy.rb', line 10 def initialize(attribute_config, policy:) @policy = policy @attribute_config = attribute_config end |
Instance Method Details
#allowed_to?(access_level) ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/resource_policy/policy/attributes_policy/attribute_policy.rb', line 27 def allowed_to?(access_level) @allowed_to ||= {} level_name = access_level.to_sym return @allowed_to[level_name] if @allowed_to.key?(level_name) @allowed_to[level_name] = fetch_allowed_to(level_name) end |
#name ⇒ Object
15 16 17 |
# File 'lib/resource_policy/policy/attributes_policy/attribute_policy.rb', line 15 def name attribute_config.name end |
#readable? ⇒ Boolean
19 20 21 |
# File 'lib/resource_policy/policy/attributes_policy/attribute_policy.rb', line 19 def readable? allowed_to?(:read) end |
#writable? ⇒ Boolean
23 24 25 |
# File 'lib/resource_policy/policy/attributes_policy/attribute_policy.rb', line 23 def writable? allowed_to?(:write) end |