Class: Conjur::Annotations

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/conjur/annotations.rb

Overview

An Annotations instance acts like a Hash: you can fetch an annotation with ‘[]’ and update with ‘[]=’, ‘each’ it, and ‘merge!’ to do bulk updates (although merge! is not more efficient than setting each pair with ‘[]=’).

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Annotations

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Annotations.



29
30
31
# File 'lib/conjur/annotations.rb', line 29

def initialize resource
  @resource = resource
end

Instance Method Details

#[](name) ⇒ Object

Get the value of the annotation with the given name a String or Symbol.

Parameters:

  • name (String, Symbol)

    the annotation name, indifferent to whether it’s



36
37
38
# File 'lib/conjur/annotations.rb', line 36

def [] name
  annotations_hash[name.to_sym]
end

#[]=(name, value) ⇒ Object

Set an annotation value

Parameters:

  • name (String, Symbol)

    the annotation name

  • value (String)

    the annotation value



43
44
45
46
# File 'lib/conjur/annotations.rb', line 43

def []= name, value
  update_annotation name, value
  value
end

#each(&blk) ⇒ Conjur::Annotations

Enumerate all annotations, yielding key,value pairs.

Returns:



50
51
52
53
# File 'lib/conjur/annotations.rb', line 50

def each &blk
  annotations_hash.each &blk
  self
end

#inspectObject



74
75
76
# File 'lib/conjur/annotations.rb', line 74

def inspect
  "<Annotations for #{@resource.resourceid}: #{to_s}>"
end

#merge!(hash) ⇒ Conjur::Annotations

Set annotations from key,value pairs in hash

Parameters:

Returns:



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

def merge! hash
  hash.each{|k,v| self[k] = v }
  self
end

#to_hHash

Return a proper hash containing a copy of ourself. Note that updates to this hash have no effect on the actual annotations.

Returns:

  • (Hash)


66
67
68
# File 'lib/conjur/annotations.rb', line 66

def to_h
  annotations_hash.dup
end

#to_sObject



70
71
72
# File 'lib/conjur/annotations.rb', line 70

def to_s
  annotations_hash.to_s
end