Class: Conjur::Graph
Overview
A Graph represents a directed graph of roles.
An instance of this class is returned by API#role_graph.
Defined Under Namespace
Classes: Edge
Instance Attribute Summary collapse
-
#edges ⇒ Array<Conjur::Graph::Edge>
readonly
Returns an array containing the directed edges of the graph.
Instance Method Summary collapse
-
#as_json(short = false) ⇒ Hash, Array
Convert the graph to a JSON serializable data structure.
-
#each_edge {|edge| ... } ⇒ Conjur::Graph
(also: #each)
Enumerates the edges of this graph.
-
#each_vertex {|vertex| ... } ⇒ Conjur::Graph
Enumerates the vertices (roles) of this graph.
-
#to_dot(name = nil) ⇒ String
Returns a string formatted for use by the graphviz dot tool.
-
#to_json(short = false) ⇒ String
Serialize the graph as JSON.
-
#vertices ⇒ Array<Conjur::Role>
(also: #roles)
Return the vertices (roles) of the graph as an array.
Instance Attribute Details
#edges ⇒ Array<Conjur::Graph::Edge> (readonly)
Returns an array containing the directed edges of the graph.
41 42 43 |
# File 'lib/conjur/graph.rb', line 41 def edges @edges end |
Instance Method Details
#as_json(short = false) ⇒ Hash, Array
Convert the graph to a JSON serializable data structure. The value returned by this method can have two
forms: An array of arrays when short
is true
, or hash like
{ 'graph' => [ {'parent' => 'roleid', 'child' => 'roleid'} ]}
otherwise.
112 113 114 115 |
# File 'lib/conjur/graph.rb', line 112 def as_json short = false edges = self.edges.map{|e| e.as_json(short)} short ? edges : {'graph' => edges} end |
#each_edge {|edge| ... } ⇒ Conjur::Graph Also known as: each
Enumerates the edges of this graph.
62 63 64 65 66 |
# File 'lib/conjur/graph.rb', line 62 def each_edge return enum_for(__method__) unless block_given? edges.each{|e| yield e} self end |
#each_vertex {|vertex| ... } ⇒ Conjur::Graph
Enumerates the vertices (roles) of this graph
73 74 75 76 |
# File 'lib/conjur/graph.rb', line 73 def each_vertex return enum_for(__method__) unless block_given? vertices.each{|v| yield v} end |
#to_dot(name = nil) ⇒ String
Returns a string formatted for use by the graphviz dot tool.
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/conjur/graph.rb', line 124 def to_dot name = nil dot = "digraph #{name || ''} {" vertices.each do |v| dot << "\n\t" << dot_node(v) end edges.each do |e| dot << "\n\t" << dot_edge(e) end dot << "\n}" end |
#to_json(short = false) ⇒ String
Serialize the graph as JSON
83 84 85 |
# File 'lib/conjur/graph.rb', line 83 def to_json short = false as_json(short).to_json end |
#vertices ⇒ Array<Conjur::Role> Also known as: roles
Return the vertices (roles) of the graph as an array.
137 138 139 |
# File 'lib/conjur/graph.rb', line 137 def vertices @vertices ||= edges.inject([]) {|a, pair| a.concat pair.to_a }.uniq end |