Class: RailsCredentialsManager::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_credentials_manager/base.rb

Direct Known Subclasses

Conflicts, Diff, Get, List, Set

Constant Summary collapse

AVAILABLE_ENVIRONMENTS =
%i[development test staging production].freeze

Instance Method Summary collapse

Constructor Details

#initialize(environment_list) ⇒ Base

Returns a new instance of Base.



5
6
7
8
# File 'lib/rails_credentials_manager/base.rb', line 5

def initialize(environment_list)
  @environment_list = environment_list.map(&:to_sym).keep_if { |env| env.to_sym.in?(AVAILABLE_ENVIRONMENTS) }
  abort pastel.red("No valid environments specified. Valid example: `-e development,test`") if @environment_list.empty?
end

Instance Method Details

#config_has_keys?(config, keys_path) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/rails_credentials_manager/base.rb', line 33

def config_has_keys?(config, keys_path)
  dig_keys = keys_path[0...-1]
  return config.key?(keys_path.first) if dig_keys.empty?

  config.dig(*dig_keys)&.key?(keys_path.last)
end

#configsObject



10
11
12
# File 'lib/rails_credentials_manager/base.rb', line 10

def configs
  @configs ||= @environment_list.inject({}) { |conf, env| conf.merge({env => config_for(env)}) }
end

#pastelObject



14
15
16
# File 'lib/rails_credentials_manager/base.rb', line 14

def pastel
  @pastel ||= Pastel.new
end


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_credentials_manager/base.rb', line 18

def print_key_and_value(key, value)
  print pastel.blue("\t#{key}:\t")

  case value
  when "not set"
    print pastel.red("not set")
  when ->(v) { v.is_a?(String) }
    print pastel.yellow(value)
  else
    print pastel.yellow(value.inspect)
  end

  print "\n"
end