gaston 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/gaston/parse.rb +18 -15
- data/lib/gaston/store.rb +4 -5
- data/lib/gaston/version.rb +1 -1
- metadata +2 -2
data/lib/gaston/parse.rb
CHANGED
@@ -16,7 +16,8 @@ class Gaston
|
|
16
16
|
@env = env
|
17
17
|
@hash = files.inject({}) do |hash, file|
|
18
18
|
parse(file)
|
19
|
-
hash
|
19
|
+
h = deep_merge(hash, default_values)
|
20
|
+
deep_merge(h, env_values)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
@@ -50,28 +51,30 @@ class Gaston
|
|
50
51
|
@parse[@env] || {}
|
51
52
|
end
|
52
53
|
|
53
|
-
#
|
54
|
+
# _why deep merge
|
54
55
|
#
|
55
|
-
#
|
56
|
+
# @return Hash
|
56
57
|
#
|
57
|
-
# @
|
58
|
-
# @param [ Hash ]
|
58
|
+
# @since 0.2.1
|
59
59
|
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
def deep_merge_hash(hash1,hash2)
|
65
|
-
hash2.each_key do |k1|
|
66
|
-
if hash1.key?(k1) && hash2[k1].is_a?(Hash)
|
67
|
-
deep_merge_hash(hash1[k1],hash2[k1])
|
60
|
+
def deep_merge(store, other)
|
61
|
+
m = proc do |key, o, n|
|
62
|
+
if o.is_a?(Hash)
|
63
|
+
o.merge(n,&m)
|
68
64
|
else
|
69
|
-
|
65
|
+
store[key] = n
|
70
66
|
end
|
71
67
|
end
|
72
|
-
|
68
|
+
store.merge(other, &m)
|
73
69
|
end
|
74
70
|
|
71
|
+
# Parse yaml or json file.
|
72
|
+
#
|
73
|
+
# @param [ String ]
|
74
|
+
#
|
75
|
+
# @return [ Hash ]
|
76
|
+
#
|
77
|
+
# @since 0.2.0
|
75
78
|
def parse(file)
|
76
79
|
erb = ERB.new(File.read(file)).result
|
77
80
|
if File.extname(file) == '.json'
|
data/lib/gaston/store.rb
CHANGED
@@ -8,13 +8,12 @@ class Gaston
|
|
8
8
|
#
|
9
9
|
# @since 0.0.1
|
10
10
|
#
|
11
|
-
def initialize(hash)
|
12
|
-
hash ||= {}
|
11
|
+
def initialize(hash={})
|
13
12
|
hash.each do |key, value|
|
14
13
|
if hash.respond_to? key
|
15
14
|
warn "#{key} method already exists on Hash, value: #{value}"
|
16
15
|
else
|
17
|
-
value.is_a?(Hash) ? self[key] =
|
16
|
+
value.is_a?(Hash) ? self[key] = self.class.new(value) : self[key] = value
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -28,7 +27,7 @@ class Gaston
|
|
28
27
|
def method_missing(method, *args, &block)
|
29
28
|
return self[method.to_s] if has_key? method.to_s
|
30
29
|
return self[method.to_sym] if has_key? method.to_sym
|
31
|
-
super
|
30
|
+
super
|
32
31
|
end
|
33
32
|
|
34
33
|
# Implement respond_to?
|
@@ -36,7 +35,7 @@ class Gaston
|
|
36
35
|
# @since 0.0.1
|
37
36
|
#
|
38
37
|
def respond_to?(method)
|
39
|
-
has_key?(method.to_s) || has_key?(method.to_sym) || super
|
38
|
+
has_key?(method.to_s) || has_key?(method.to_sym) || super
|
40
39
|
end
|
41
40
|
|
42
41
|
end # Store
|
data/lib/gaston/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gaston
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|