Class: CedarPolicy::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/cedar_policy/entity.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid, attrs = {}, parents = []) ⇒ Entity

Returns a new instance of Entity.

Raises:

  • (ArgumentError)


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

#attrsObject (readonly)

Returns the value of attribute attrs.



6
7
8
# File 'lib/cedar_policy/entity.rb', line 6

def attrs
  @attrs
end

#parentsObject (readonly)

Returns the value of attribute parents.



6
7
8
# File 'lib/cedar_policy/entity.rb', line 6

def parents
  @parents
end

#uidObject (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

Returns:

  • (Boolean)


20
21
22
# File 'lib/cedar_policy/entity.rb', line 20

def eql?(other)
  hash == other.hash
end

#hashObject



24
25
26
# File 'lib/cedar_policy/entity.rb', line 24

def hash
  [self.class, @uid].hash
end

#to_hashObject



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