Class: Conjur::Graph::Edge

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(parent, child) ⇒ Edge

Create a directed edge with a parent and child

Parameters:

  • parent (Conjur::Role)

    the parent or source of this edge

  • child (Conjur::Role)

    the child or destination of this edge



219
220
221
222
# File 'lib/conjur/graph.rb', line 219

def initialize parent, child
  @parent = parent
  @child = child
end

Instance Attribute Details

#childConjur::Role (readonly)

Return the child of this edge. The #parent role is a member of the #child role.

Returns:



213
214
215
# File 'lib/conjur/graph.rb', line 213

def child
  @child
end

#parentConjur::Role (readonly)

Return the parent of this edge. The #parent role is a member of the #child role.

Returns:



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"}.

Parameters:

  • short (Boolean) (defaults to: false)

    return an Array when true, otherwise return a Hash.

Returns:

  • (Array, Hash)

    value suitable for JSON serialization



240
241
242
# File 'lib/conjur/graph.rb', line 240

def as_json short = false
  short ? to_a : to_h
end

#to_aArray<String>

Return this edge as an Array like ["parent", "child"]

Returns:

  • (Array<String>)

    the edge as an Array



257
258
259
# File 'lib/conjur/graph.rb', line 257

def to_a
  [@parent, @child]
end

#to_hHash

Return this edge as a Hash like => "...", "child" => "...".

Note that the keys in the hash are strings.

Returns:

  • (Hash)

    a Hash representing this edge



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.

Parameters:

  • short (Boolean) (defaults to: false)

    when true, serialize the edge as an Array instead of a Hash

Returns:

  • (String)

    the JSON serialized edge

See Also:



229
230
231
# File 'lib/conjur/graph.rb', line 229

def to_json short = false
  as_json(short).to_json
end