Class: CedarPolicy::Entity
- Inherits:
-
Object
- Object
- CedarPolicy::Entity
- Defined in:
- lib/cedar_policy/entity.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#parents ⇒ Object
readonly
Returns the value of attribute parents.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(uid, attrs = {}, parents = []) ⇒ Entity
constructor
A new instance of Entity.
- #to_hash ⇒ Object
Constructor Details
#initialize(uid, attrs = {}, parents = []) ⇒ Entity
Returns a new instance of Entity.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cedar_policy/entity.rb', line 8 def initialize(uid, attrs = {}, parents = []) raise ArgumentError unless uid.is_a?(EntityUid) || uid.is_a?(Hash) @uid = if uid.is_a?(EntityUid) uid else EntityUid.new(*uid.values_at(:type, :id)) end @attrs = attrs @parents = Set.new(parents) end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
6 7 8 |
# File 'lib/cedar_policy/entity.rb', line 6 def attrs @attrs end |
#parents ⇒ Object (readonly)
Returns the value of attribute parents.
6 7 8 |
# File 'lib/cedar_policy/entity.rb', line 6 def parents @parents end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
6 7 8 |
# File 'lib/cedar_policy/entity.rb', line 6 def uid @uid end |
Instance Method Details
#eql?(other) ⇒ Boolean
20 21 22 |
# File 'lib/cedar_policy/entity.rb', line 20 def eql?(other) hash == other.hash end |
#hash ⇒ Object
24 25 26 |
# File 'lib/cedar_policy/entity.rb', line 24 def hash [self.class, @uid].hash end |
#to_hash ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/cedar_policy/entity.rb', line 28 def to_hash { uid: @uid, attrs: @attrs, parents: @parents.to_a } end |