Class: KeyStore::Key
- Inherits:
-
Object
- Object
- KeyStore::Key
- Extended by:
- Forwardable
- Defined in:
- lib/key_store/key.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Instance Method Summary collapse
- #http_header ⇒ Object
-
#initialize(name, roles: nil, notes: nil) ⇒ Key
constructor
A new instance of Key.
- #save! ⇒ Object
Constructor Details
#initialize(name, roles: nil, notes: nil) ⇒ Key
Returns a new instance of Key.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/key_store/key.rb', line 12 def initialize(name, roles: nil, notes: nil) @name = name.to_s if exists?(name) set_roles_from_file if roles.nil? set_notes_from_file if notes.nil? end @roles ||= (roles || []).map(&:to_s) @notes ||= notes.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
8 9 10 |
# File 'lib/key_store/key.rb', line 8 def name @name end |
#notes ⇒ Object
Returns the value of attribute notes.
9 10 11 |
# File 'lib/key_store/key.rb', line 9 def notes @notes end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
8 9 10 |
# File 'lib/key_store/key.rb', line 8 def roles @roles end |
Instance Method Details
#http_header ⇒ Object
24 25 26 |
# File 'lib/key_store/key.rb', line 24 def http_header "Authorization: Token token=\"#{name}\"" end |
#save! ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/key_store/key.rb', line 28 def save! file.transaction do |f| f[name] ||= {} f[name][:roles] = roles.map(&:to_s) f[name][:notes] = notes.to_s f[name][:http_header] = http_header end end |