Class: ResourcePolicy::Policy::ActionsPolicy::ActionPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/resource_policy/policy/actions_policy/action_policy.rb

Overview

Contains information about single action

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, policy:) ⇒ ActionPolicy

Returns a new instance of ActionPolicy.



10
11
12
13
# File 'lib/resource_policy/policy/actions_policy/action_policy.rb', line 10

def initialize(name, policy:)
  @name = name.to_sym
  @policy = policy
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/resource_policy/policy/actions_policy/action_policy.rb', line 8

def name
  @name
end

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/resource_policy/policy/actions_policy/action_policy.rb', line 15

def allowed?
  return @allowed if defined?(@allowed)

  conditions = policy_config.action(name).conditions
  @allowed = conditions.all? { |condition| policy.send(condition) }
end