Class: ResourcePolicy::Policy::AttributesPolicy::AttributePolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/resource_policy/policy/attributes_policy/attribute_policy.rb

Overview

Stores information about access level of single attribute.

Instance Method Summary collapse

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

Returns:

  • (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

#nameObject



15
16
17
# File 'lib/resource_policy/policy/attributes_policy/attribute_policy.rb', line 15

def name
  attribute_config.name
end

#readable?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/resource_policy/policy/attributes_policy/attribute_policy.rb', line 19

def readable?
  allowed_to?(:read)
end

#writable?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/resource_policy/policy/attributes_policy/attribute_policy.rb', line 23

def writable?
  allowed_to?(:write)
end