Class: PM::Association
- Inherits:
-
Object
- Object
- PM::Association
- Defined in:
- lib/policy_machine/association.rb
Instance Attribute Summary collapse
-
#object_attribute ⇒ Object
Returns the value of attribute object_attribute.
-
#operation_set ⇒ Object
Returns the value of attribute operation_set.
-
#user_attribute ⇒ Object
Returns the value of attribute user_attribute.
Class Method Summary collapse
-
.create(user_attribute_pe, operation_set, object_attribute_pe, policy_machine_uuid, pm_storage_adapter) ⇒ Object
Create an association given persisted policy elements.
Instance Method Summary collapse
-
#includes_operation?(operation) ⇒ Boolean
Returns true if the operation set of this association includes the given operation.
-
#initialize(stored_user_attribute, stored_operation_set, stored_object_attribute, pm_storage_adapter) ⇒ Association
constructor
A new instance of Association.
Constructor Details
#initialize(stored_user_attribute, stored_operation_set, stored_object_attribute, pm_storage_adapter) ⇒ Association
Returns a new instance of Association.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/policy_machine/association.rb', line 7 def initialize(stored_user_attribute, stored_operation_set, stored_object_attribute, pm_storage_adapter) @user_attribute = PM::PolicyElement.convert_stored_pe_to_pe( stored_user_attribute, pm_storage_adapter, PM::UserAttribute ) @operation_set = Set.new stored_operation_set.each do |stored_op| op = PM::PolicyElement.convert_stored_pe_to_pe( stored_op, pm_storage_adapter, PM::Operation ) @operation_set << op end @object_attribute = PM::PolicyElement.convert_stored_pe_to_pe( stored_object_attribute, pm_storage_adapter, PM::ObjectAttribute ) end |
Instance Attribute Details
#object_attribute ⇒ Object
Returns the value of attribute object_attribute.
5 6 7 |
# File 'lib/policy_machine/association.rb', line 5 def object_attribute @object_attribute end |
#operation_set ⇒ Object
Returns the value of attribute operation_set.
4 5 6 |
# File 'lib/policy_machine/association.rb', line 4 def operation_set @operation_set end |
#user_attribute ⇒ Object
Returns the value of attribute user_attribute.
3 4 5 |
# File 'lib/policy_machine/association.rb', line 3 def user_attribute @user_attribute end |
Class Method Details
.create(user_attribute_pe, operation_set, object_attribute_pe, policy_machine_uuid, pm_storage_adapter) ⇒ Object
Create an association given persisted policy elements
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/policy_machine/association.rb', line 40 def self.create(user_attribute_pe, operation_set, object_attribute_pe, policy_machine_uuid, pm_storage_adapter) # argument errors for user_attribute_pe raise(ArgumentError, "user_attribute_pe must be a UserAttribute.") unless user_attribute_pe.is_a?(PM::UserAttribute) unless user_attribute_pe.policy_machine_uuid == policy_machine_uuid raise(ArgumentError, "user_attribute_pe must be in policy machine with uuid #{policy_machine_uuid}") end # argument errors for operation_set raise(ArgumentError, "operation_set must be a Set of Operations") unless operation_set.is_a?(Set) raise(ArgumentError, "operation_set must not be empty") if operation_set.empty? operation_set.each do |op| unless op.is_a?(PM::Operation) raise(ArgumentError, "expected #{op} to be PM::Operation; got #{op.class}") end unless op.policy_machine_uuid == policy_machine_uuid raise(ArgumentError, "expected #{op.unique_identifier} to be in Policy Machine with uuid #{policy_machine_uuid}; got #{op.policy_machine_uuid}") end end # argument errors for object_attribute_pe raise(ArgumentError, "object_attribute_pe must be an ObjectAttribute.") unless object_attribute_pe.is_a?(PM::ObjectAttribute) unless object_attribute_pe.policy_machine_uuid == policy_machine_uuid raise(ArgumentError, "object_attribute_pe must be in policy machine with uuid #{policy_machine_uuid}") end new_assoc = pm_storage_adapter.add_association( user_attribute_pe.stored_pe, Set.new(operation_set.map(&:stored_pe)), object_attribute_pe.stored_pe, policy_machine_uuid ) end |
Instance Method Details
#includes_operation?(operation) ⇒ Boolean
Returns true if the operation set of this association includes the given operation.
33 34 35 36 |
# File 'lib/policy_machine/association.rb', line 33 def includes_operation?(operation) # Note: operation_set.member? isn't calling PM::PolicyElement == operation_set.any?{ |op| op == operation } end |