Class: Secretmgr::Config
- Inherits:
-
Object
- Object
- Secretmgr::Config
- Defined in:
- lib/secretmgr/config.rb
Instance Method Summary collapse
- #file_format(*keys) ⇒ Object
- #get_file_path(parent_dir_pn, *keys) ⇒ Object
-
#initialize(parent_pn, format_filename = "format.txt") ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(parent_pn, format_filename = "format.txt") ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 |
# File 'lib/secretmgr/config.rb', line 8 def initialize(parent_pn, format_filename = "format.txt") format_pn = Pathname.new(parent_pn) + format_filename file_content = File.read(format_pn) @hash = YAML.safe_load(file_content) end |
Instance Method Details
#file_format(*keys) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/secretmgr/config.rb', line 14 def file_format(*keys) result = keys.flatten.each_with_object([@hash]) do |item, memo| hash = memo[0] memo[0] = if hash (hash.instance_of?(Hash) ? hash[item] : nil) end end Loggerxs.debug "hash=#{hash}" result ? (result[0] || @hash["default"]) : @hash["default"] end |
#get_file_path(parent_dir_pn, *keys) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/secretmgr/config.rb', line 25 def get_file_path(parent_dir_pn, *keys) flat_keys = keys.flatten valid_keys = flat_keys.compact file_format = file_format(valid_keys) case file_format when "JSON_FILE" flat_keys.unshift("JSON_FILE") flat_keys.push("config.json") when "YAML" flat_keys = ["secret.yml"] end array = flat_keys.each_with_object([parent_dir_pn]) do |item, memo| memo[0] = memo[0] + item if item end array[0] end |