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
-
#admin_option ⇒ Object
(also: #admin_option?)
readonly
Was the role granted with admin_option? May be nil if unknown (e.g. if the server doesn't return it).
-
#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, admin_option = nil) ⇒ 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, admin_option = nil) ⇒ Edge
Create a directed edge with a parent and child
224 225 226 227 228 |
# File 'lib/conjur/graph.rb', line 224 def initialize parent, child, admin_option = nil @parent = parent @child = child @admin_option = admin_option end |
Instance Attribute Details
#admin_option ⇒ Object (readonly) Also known as: admin_option?
Was the role granted with admin_option? May be nil if unknown (e.g. if the server doesn't return it).
217 218 219 |
# File 'lib/conjur/graph.rb', line 217 def admin_option @admin_option end |
#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"}
.
246 247 248 |
# File 'lib/conjur/graph.rb', line 246 def as_json short = false short ? to_a : to_h end |
#to_a ⇒ Array<String>
Return this edge as an Array like ["parent", "child"]
263 264 265 |
# File 'lib/conjur/graph.rb', line 263 def to_a [@parent, @child].tap {|a| a.push(@admin_option) unless @admin_option.nil?} end |
#to_h ⇒ Hash
Return this edge as a Hash like => "...", "child" => "...".
Note that the keys in the hash are strings.
255 256 257 258 |
# File 'lib/conjur/graph.rb', line 255 def to_h # return string keys to make testing less brittle {'parent' => @parent, 'child' => @child}.tap {|h| h['admin_option'] = @admin_option unless @admin_option.nil?} end |
#to_json(short = false) ⇒ String
Serialize this edge as JSON.
235 236 237 |
# File 'lib/conjur/graph.rb', line 235 def to_json short = false as_json(short).to_json end |