Class: Conjur::Graph::Edge
- Inherits:
-
Object
- Object
- Conjur::Graph::Edge
- Defined in:
- lib/conjur/graph.rb
Overview
Represents a directed Edge between a parent role and a child role.
In this context, the parent role is a member of the child role. For example,
the admin
role is a parent of every role, either directly or indirectly, because
it is added as a member to all roles it creates.
Instance Attribute Summary collapse
-
#child ⇒ Conjur::Role
readonly
Return the child of this edge.
-
#parent ⇒ Conjur::Role
readonly
Return the parent of this edge.
Instance Method Summary collapse
-
#as_json(short = false) ⇒ Array, Hash
Return a value suitable for JSON serialization.
-
#initialize(parent, child) ⇒ Edge
constructor
Create a directed edge with a parent and child.
-
#to_a ⇒ Array<String>
Return this edge as an Array like ["parent", "child"].
-
#to_h ⇒ Hash
Return this edge as a Hash like => "...", "child" => "...".
-
#to_json(short = false) ⇒ String
Serialize this edge as JSON.
Constructor Details
#initialize(parent, child) ⇒ Edge
Create a directed edge with a parent and child
219 220 221 222 |
# File 'lib/conjur/graph.rb', line 219 def initialize parent, child @parent = parent @child = child end |
Instance Attribute Details
#child ⇒ Conjur::Role (readonly)
213 214 215 |
# File 'lib/conjur/graph.rb', line 213 def child @child end |
#parent ⇒ Conjur::Role (readonly)
209 210 211 |
# File 'lib/conjur/graph.rb', line 209 def parent @parent end |
Instance Method Details
#as_json(short = false) ⇒ Array, Hash
Return a value suitable for JSON serialization.
The short
parameter determines whether to return a ["parent", "child"]
Array
or a Hash like {"parent" => "parent-role", "child" => "child-role"}
.
240 241 242 |
# File 'lib/conjur/graph.rb', line 240 def as_json short = false short ? to_a : to_h end |
#to_a ⇒ Array<String>
Return this edge as an Array like ["parent", "child"]
257 258 259 |
# File 'lib/conjur/graph.rb', line 257 def to_a [@parent, @child] end |
#to_h ⇒ Hash
Return this edge as a Hash like => "...", "child" => "...".
Note that the keys in the hash are strings.
249 250 251 252 |
# File 'lib/conjur/graph.rb', line 249 def to_h # return string keys to make testing less brittle {'parent' => @parent, 'child' => @child} end |
#to_json(short = false) ⇒ String
Serialize this edge as JSON.
229 230 231 |
# File 'lib/conjur/graph.rb', line 229 def to_json short = false as_json(short).to_json end |