Class: Makit::Secrets
- Inherits:
-
Object
- Object
- Makit::Secrets
- Defined in:
- lib/makit/secrets.rb
Instance Method Summary collapse
- #add(key, value) ⇒ Object
- #get(key) ⇒ Object
- #get_secrets_filename ⇒ Object
- #get_secrets_hash ⇒ Object
- #has_key?(key) ⇒ Boolean
- #remove(key) ⇒ Object
- #save_secrets_hash(hash) ⇒ Object
- #set(key, value) ⇒ Object
Instance Method Details
#add(key, value) ⇒ Object
5 6 7 8 9 |
# File 'lib/makit/secrets.rb', line 5 def add(key, value) secrets_hash = get_secrets_hash secrets_hash[key] = value save_secrets_hash(secrets_hash) end |
#get(key) ⇒ Object
22 23 24 25 |
# File 'lib/makit/secrets.rb', line 22 def get(key) secrets_hash = get_secrets_hash secrets_hash[key] end |
#get_secrets_filename ⇒ Object
33 34 35 |
# File 'lib/makit/secrets.rb', line 33 def get_secrets_filename "#{Makit::Directories::ROOT}/secrets.json" end |
#get_secrets_hash ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/makit/secrets.rb', line 37 def get_secrets_hash secrets_file = get_secrets_filename return {} unless File.exist?(secrets_file) text = File.read(secrets_file) JSON.parse(text) end |
#has_key?(key) ⇒ Boolean
17 18 19 20 |
# File 'lib/makit/secrets.rb', line 17 def has_key?(key) secrets_hash = get_secrets_hash secrets_hash.key?(key) end |
#remove(key) ⇒ Object
11 12 13 14 15 |
# File 'lib/makit/secrets.rb', line 11 def remove(key) secrets_hash = get_secrets_hash secrets_hash.delete(key) save_secrets_hash(secrets_hash) end |
#save_secrets_hash(hash) ⇒ Object
45 46 47 48 49 |
# File 'lib/makit/secrets.rb', line 45 def save_secrets_hash(hash) secrets_file = get_secrets_filename # pretty print the hash File.open(secrets_file, "w") { |f| f.puts JSON.pretty_generate(hash) } end |
#set(key, value) ⇒ Object
27 28 29 30 31 |
# File 'lib/makit/secrets.rb', line 27 def set(key, value) secrets_hash = get_secrets_hash secrets_hash[key] = value save_secrets_hash(secrets_hash) end |