Class: ResourcePolicy::Policy::AttributesPolicy::AttributesPolicyModel

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

Overview

Class which isolates methods defined via attributes_policy config

Instance Method Summary collapse

Constructor Details

#initialize(policy) ⇒ AttributesPolicyModel

Returns a new instance of AttributesPolicyModel.



10
11
12
13
# File 'lib/resource_policy/policy/attributes_policy/attributes_policy_model.rb', line 10

def initialize(policy)
  @policy = policy
  @policy_item_by_name ||= {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



25
26
27
28
29
# File 'lib/resource_policy/policy/attributes_policy/attributes_policy_model.rb', line 25

def method_missing(method_name)
  return super unless config.attributes.key?(method_name.to_sym)

  policy_item(method_name.to_sym)
end

Instance Method Details

#allObject



15
16
17
18
19
# File 'lib/resource_policy/policy/attributes_policy/attributes_policy_model.rb', line 15

def all
  @all ||= config.attributes.keys.map do |attribute_name|
    policy_item(attribute_name)
  end
end

#all_allowed_to(status) ⇒ Object



21
22
23
# File 'lib/resource_policy/policy/attributes_policy/attributes_policy_model.rb', line 21

def all_allowed_to(status)
  all.select { |attribute| attribute.allowed_to?(status) }
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/resource_policy/policy/attributes_policy/attributes_policy_model.rb', line 31

def respond_to_missing?(method_name, *args)
  config.attributes.key?(method_name.to_sym) || super
end