Skip to content

Commit ef1b8d8

Browse files
committed
tuck ComposeRefinements under the Bashly namespace
1 parent eaa13aa commit ef1b8d8

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed
Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
1-
module ComposeRefinements
2-
refine Hash do
3-
def compose(keyword = 'import')
4-
result = {}
5-
each do |k, v|
6-
if k.to_s == keyword
7-
sub = safe_load_yaml(v).compose keyword
8-
if sub.is_a? Array
9-
result = sub
1+
module Bashly
2+
module ComposeRefinements
3+
refine Hash do
4+
def compose(keyword = 'import')
5+
result = {}
6+
each do |k, v|
7+
if k.to_s == keyword
8+
sub = safe_load_yaml(v).compose keyword
9+
if sub.is_a? Array
10+
result = sub
11+
else
12+
result.merge! sub
13+
end
14+
elsif v.respond_to? :compose
15+
result[k] = v.compose keyword
1016
else
11-
result.merge! sub
17+
result[k] = v
1218
end
13-
elsif v.respond_to? :compose
14-
result[k] = v.compose keyword
15-
else
16-
result[k] = v
1719
end
20+
result
1821
end
19-
result
20-
end
2122

22-
def safe_load_yaml(path)
23-
loaded = YAML.load_erb_file path
24-
return loaded if loaded.is_a?(Array) || loaded.is_a?(Hash)
23+
def safe_load_yaml(path)
24+
loaded = YAML.load_erb_file path
25+
return loaded if loaded.is_a?(Array) || loaded.is_a?(Hash)
2526

26-
raise Bashly::ConfigurationError, "Cannot find a valid YAML in g`#{path}`"
27-
rescue Errno::ENOENT
28-
raise Bashly::ConfigurationError, "Cannot find import file g`#{path}`"
27+
raise Bashly::ConfigurationError, "Cannot find a valid YAML in g`#{path}`"
28+
rescue Errno::ENOENT
29+
raise Bashly::ConfigurationError, "Cannot find import file g`#{path}`"
30+
end
2931
end
30-
end
3132

32-
refine Array do
33-
def compose(keyword = 'import')
34-
map do |x|
35-
if x.respond_to? :compose
36-
x.compose keyword
37-
else
38-
x
33+
refine Array do
34+
def compose(keyword = 'import')
35+
map do |x|
36+
if x.respond_to? :compose
37+
x.compose keyword
38+
else
39+
x
40+
end
3941
end
4042
end
4143
end
4244
end
43-
end
45+
end

0 commit comments

Comments
 (0)