Class: Raykit::Secrets

Inherits:
Hash
  • Object
show all
Defined in:
lib/raykit/secrets.rb

Overview

Provides functionality to record the time execution times

Instance Method Summary collapse

Constructor Details

#initializeSecrets

Returns a new instance of Secrets.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/raykit/secrets.rb', line 8

def initialize
  if ENV.key?("RAYKIT_SECRETS_PATH")
    secrets_file = ENV["RAYKIT_SECRETS_PATH"]
    if File.exist?(secrets_file)
      text = IO.read(secrets_file)
      if text.length > 7
        data = JSON.parse(text)
        data.each do |key, value|
          self[key] = value
        end
      end
    end
  end
end

Instance Method Details

#hide(text) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/raykit/secrets.rb', line 23

def hide(text)
  hidden = text
  each do |_k, v|
    hidden = hidden.gsub(v, "****") if !v.nil? && v.length.positive?
  end
  hidden
end

#saveObject



31
32
33
34
35
36
# File 'lib/raykit/secrets.rb', line 31

def save
  if ENV.key?("RAYKIT_SECRETS_PATH")
    secrets_file = ENV["RAYKIT_SECRETS_PATH"]
    File.open(secrets_file, "w") { |f| f.puts to_json }
  end
end