Class: Conjur::Annotations
- Inherits:
-
Object
- Object
- Conjur::Annotations
- 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
-
#[](name) ⇒ Object
Get the value of the annotation with the given name a String or Symbol.
-
#[]=(name, value) ⇒ Object
Set an annotation value.
-
#each(&blk) ⇒ Conjur::Annotations
Enumerate all annotations, yielding key,value pairs.
-
#initialize(resource) ⇒ Annotations
constructor
private
A new instance of Annotations.
- #inspect ⇒ Object
-
#merge!(hash) ⇒ Conjur::Annotations
Set annotations from key,value pairs in
hash
. -
#to_h ⇒ Hash
Return a proper hash containing a
copy
of ourself. - #to_s ⇒ Object
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.
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
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.
50 51 52 53 |
# File 'lib/conjur/annotations.rb', line 50 def each &blk annotations_hash.each &blk self end |
#inspect ⇒ Object
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
58 59 60 61 |
# File 'lib/conjur/annotations.rb', line 58 def merge! hash hash.each{|k,v| self[k] = v } self end |
#to_h ⇒ Hash
Return a proper hash containing a copy
of ourself. Note that updates to this hash have no effect on the actual annotations.
66 67 68 |
# File 'lib/conjur/annotations.rb', line 66 def to_h annotations_hash.dup end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/conjur/annotations.rb', line 70 def to_s annotations_hash.to_s end |