Class: Slosilo::Keystore
- Inherits:
-
Object
- Object
- Slosilo::Keystore
- Defined in:
- lib/slosilo/keystore.rb
Instance Method Summary collapse
- #adapter ⇒ Object
- #any?(&block) ⇒ Boolean
- #each(&_) ⇒ Object
- #get(opts) ⇒ Object
- #get_by_fingerprint(fingerprint) ⇒ Object
- #put(id, key) ⇒ Object
Instance Method Details
#adapter ⇒ Object
5 6 7 |
# File 'lib/slosilo/keystore.rb', line 5 def adapter Slosilo::adapter or raise "No Slosilo adapter is configured or available" end |
#any?(&block) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/slosilo/keystore.rb', line 33 def any? &block each do |_, k| return true if yield k end return false end |
#each(&_) ⇒ Object
29 30 31 |
# File 'lib/slosilo/keystore.rb', line 29 def each &_ adapter.each { |k, v| yield k, v } end |
#get(opts) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/slosilo/keystore.rb', line 15 def get opts id, fingerprint = opts.is_a?(Hash) ? [nil, opts[:fingerprint]] : [opts, nil] if id key = adapter.get_key(id.to_s) elsif fingerprint key, _ = get_by_fingerprint(fingerprint) end key end |
#get_by_fingerprint(fingerprint) ⇒ Object
25 26 27 |
# File 'lib/slosilo/keystore.rb', line 25 def get_by_fingerprint fingerprint adapter.get_by_fingerprint fingerprint end |
#put(id, key) ⇒ Object
9 10 11 12 13 |
# File 'lib/slosilo/keystore.rb', line 9 def put id, key id = id.to_s fail ArgumentError, "id can't be empty" if id.empty? adapter.put_key id, key end |