From ef1b8d85aa6f8edb72445f4c35e2882e626db34f Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Thu, 29 Feb 2024 05:17:26 +0000 Subject: [PATCH] tuck ComposeRefinements under the Bashly namespace --- lib/bashly/refinements/compose_refinements.rb | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/lib/bashly/refinements/compose_refinements.rb b/lib/bashly/refinements/compose_refinements.rb index 66a4761b..570a1dd3 100644 --- a/lib/bashly/refinements/compose_refinements.rb +++ b/lib/bashly/refinements/compose_refinements.rb @@ -1,43 +1,45 @@ -module ComposeRefinements - refine Hash do - def compose(keyword = 'import') - result = {} - each do |k, v| - if k.to_s == keyword - sub = safe_load_yaml(v).compose keyword - if sub.is_a? Array - result = sub +module Bashly + module ComposeRefinements + refine Hash do + def compose(keyword = 'import') + result = {} + each do |k, v| + if k.to_s == keyword + sub = safe_load_yaml(v).compose keyword + if sub.is_a? Array + result = sub + else + result.merge! sub + end + elsif v.respond_to? :compose + result[k] = v.compose keyword else - result.merge! sub + result[k] = v end - elsif v.respond_to? :compose - result[k] = v.compose keyword - else - result[k] = v end + result end - result - end - def safe_load_yaml(path) - loaded = YAML.load_erb_file path - return loaded if loaded.is_a?(Array) || loaded.is_a?(Hash) + def safe_load_yaml(path) + loaded = YAML.load_erb_file path + return loaded if loaded.is_a?(Array) || loaded.is_a?(Hash) - raise Bashly::ConfigurationError, "Cannot find a valid YAML in g`#{path}`" - rescue Errno::ENOENT - raise Bashly::ConfigurationError, "Cannot find import file g`#{path}`" + raise Bashly::ConfigurationError, "Cannot find a valid YAML in g`#{path}`" + rescue Errno::ENOENT + raise Bashly::ConfigurationError, "Cannot find import file g`#{path}`" + end end - end - refine Array do - def compose(keyword = 'import') - map do |x| - if x.respond_to? :compose - x.compose keyword - else - x + refine Array do + def compose(keyword = 'import') + map do |x| + if x.respond_to? :compose + x.compose keyword + else + x + end end end end end -end +end \ No newline at end of file