Class: Conjur::Id

Inherits:
Object
  • Object
show all
Includes:
Escape
Defined in:
lib/conjur/id.rb

Overview

Encapsulates a Conjur id, which consists of account, kind, and identifier.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Escape

#fully_escape, #path_escape, #query_escape

Constructor Details

#initialize(id) ⇒ Id

Returns a new instance of Id.



30
31
32
# File 'lib/conjur/id.rb', line 30

def initialize id
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



28
29
30
# File 'lib/conjur/id.rb', line 28

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object

Defines id equivalence using the string representation.



43
44
45
46
47
48
49
# File 'lib/conjur/id.rb', line 43

def == other
  if other.is_a?(String)
    to_s == other
  else
    super
  end
end

#accountObject

The organization account, obtained from the first component of the id.



35
# File 'lib/conjur/id.rb', line 35

def ; id.split(':', 3)[0]; end

#as_json(options = {}) ⇒ String

Returns the id string.

Returns:

  • (String)

    the id string.



52
53
54
# File 'lib/conjur/id.rb', line 52

def as_json options={}
  @id
end

#identifierObject

The object identifier, obtained from the third component of the id. The identifier must be unique within the account and kind.



40
# File 'lib/conjur/id.rb', line 40

def identifier; id.split(':', 3)[2]; end

#kindObject

The object kind, obtained from the second component of the id.



37
# File 'lib/conjur/id.rb', line 37

def kind; id.split(':', 3)[1]; end

#to_sString

Returns the id string.

Returns:

  • (String)

    the id string



64
65
66
# File 'lib/conjur/id.rb', line 64

def to_s
  id
end

#to_url_pathObject

Splits the id into 3 components, and then joins them with a forward-slash /.



57
58
59
60
61
# File 'lib/conjur/id.rb', line 57

def to_url_path
  id.split(':', 3)
    .map(&method(:path_escape))
    .join('/')
end