lib/runger/loaders/ejson.rb in runger_config-4.0.0 vs lib/runger/loaders/ejson.rb in runger_config-5.0.0

- old
+ new

@@ -1,89 +1,91 @@ # frozen_string_literal: true -require "runger/ejson_parser" +require 'runger/ejson_parser' -module Runger - module Loaders - class EJSON < Base - class << self - attr_accessor :bin_path - end +class Runger::Loaders::EJSON < Runger::Loaders::Base + class << self + attr_accessor :bin_path + end - self.bin_path = "ejson" + self.bin_path = 'ejson' - def call(name:, ejson_namespace: name, ejson_parser: Runger::EJSONParser.new(EJSON.bin_path), **_options) - configs = [] + def call( + name:, + ejson_namespace: name, + ejson_parser: Runger::EJSONParser.new(Runger::Loaders::EJSON.bin_path), + **_options + ) + configs = [] - rel_config_paths.each do |rel_config_path| - secrets_hash, rel_path = - extract_hash_from_rel_config_path( - ejson_parser: ejson_parser, - rel_config_path: rel_config_path - ) + rel_config_paths.each do |rel_config_path| + secrets_hash, rel_path = + extract_hash_from_rel_config_path( + ejson_parser:, + rel_config_path:, + ) - next unless secrets_hash + next unless secrets_hash - config_hash = if ejson_namespace - secrets_hash[ejson_namespace] - else - secrets_hash.except("_public_key") - end - - next unless config_hash.is_a?(Hash) - - configs << - trace!(:ejson, path: rel_path) do - config_hash - end + config_hash = + if ejson_namespace + secrets_hash[ejson_namespace] + else + secrets_hash.except('_public_key') end - return {} if configs.empty? + next unless config_hash.is_a?(Hash) - configs.inject do |result_config, next_config| - Utils.deep_merge!(result_config, next_config) + configs << + trace!(:ejson, path: rel_path) do + config_hash end - end + end - private + return {} if configs.empty? - def rel_config_paths - chain = [environmental_rel_config_path] + configs.inject do |result_config, next_config| + ::Runger::Utils.deep_merge!(result_config, next_config) + end + end - chain << "secrets.local.ejson" if use_local? + private - chain - end + def rel_config_paths + chain = [environmental_rel_config_path] - def environmental_rel_config_path - if Settings.current_environment - # if environment file is absent, then take data from the default one - [ - "#{Settings.current_environment}/secrets.ejson", - default_rel_config_path - ] - else - default_rel_config_path - end - end + chain << 'secrets.local.ejson' if use_local? - def default_rel_config_path - "secrets.ejson" - end + chain + end - def extract_hash_from_rel_config_path(ejson_parser:, rel_config_path:) - rel_config_path = [rel_config_path] unless rel_config_path.is_a?(Array) + def environmental_rel_config_path + if ::Runger::Settings.current_environment + # if environment file is absent, then take data from the default one + [ + "#{::Runger::Settings.current_environment}/secrets.ejson", + default_rel_config_path, + ] + else + default_rel_config_path + end + end - rel_config_path.each do |rel_conf_path| - rel_path = "config/#{rel_conf_path}" - abs_path = "#{Settings.app_root}/#{rel_path}" + def default_rel_config_path + 'secrets.ejson' + end - result = ejson_parser.call(abs_path) + def extract_hash_from_rel_config_path(ejson_parser:, rel_config_path:) + rel_config_path = Array(rel_config_path) - return [result, rel_path] if result - end + rel_config_path.each do |rel_conf_path| + rel_path = "config/#{rel_conf_path}" + abs_path = "#{::Runger::Settings.app_root}/#{rel_path}" - nil - end + result = ejson_parser.call(abs_path) + + return [result, rel_path] if result end + + nil end end