has_configuration 1.0.0 → 2.0.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.
- checksums.yaml +4 -4
- data/lib/has_configuration/configuration.rb +25 -18
- data/lib/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e711006bd79831f88942f6a8f00c73adda21e06
|
4
|
+
data.tar.gz: cae116f13df37c98c094537f77528acb37f0c5bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f431a7d22c52c614fad01600be733548ec56bc5fdb21c7dcf6ec43ef6a9f89799d53936287529cab904666defff2abc6ab75ccdf94272087a206246a7287b75f
|
7
|
+
data.tar.gz: aba4ca638e262bf0c625e56ad9f49386d8c269de18e77d94b8717147c00633a2e236e093e98820d39caf0b0d6707993acc2dc863dc2f3fb1a5e7d6af3641ca50
|
@@ -20,19 +20,28 @@ module HasConfiguration #:nodoc:
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
private
|
24
24
|
|
25
25
|
def method_missing(sym, *args, &block)
|
26
|
-
configuration.send(sym, *args, &block)
|
26
|
+
configuration.send(sym, *args, &block) || super
|
27
|
+
end
|
28
|
+
|
29
|
+
def respond_to_missing?(sym, include_private = false)
|
30
|
+
configuration.respond_to?(sym, include_private)
|
27
31
|
end
|
28
32
|
|
29
33
|
def load_file
|
30
|
-
@raw = YAML.
|
34
|
+
@raw = YAML.safe_load(
|
35
|
+
ERB.new(raw_file(filename)).result,
|
36
|
+
[], # whitelist_classes
|
37
|
+
[], # whitelist_symbols
|
38
|
+
true # allow aliases
|
39
|
+
)
|
31
40
|
end
|
32
41
|
|
33
42
|
def init_hash
|
34
43
|
@hash = (@raw || {}).with_indifferent_access
|
35
|
-
@hash = @hash[environment]
|
44
|
+
@hash = @hash[environment] if environment
|
36
45
|
end
|
37
46
|
|
38
47
|
def raw_file(filename)
|
@@ -50,23 +59,19 @@ module HasConfiguration #:nodoc:
|
|
50
59
|
filename = "#{@class_name.downcase}.yml"
|
51
60
|
defined?(Rails) ? Rails.root.join('config', filename).to_s : filename
|
52
61
|
else
|
53
|
-
|
54
|
-
|
62
|
+
raise ArgumentError,
|
63
|
+
'Unable to resolve filename, please add :file parameter to has_configuration'
|
55
64
|
end
|
56
65
|
end
|
57
66
|
|
58
67
|
def environment
|
59
|
-
|
60
|
-
|
61
|
-
when defined?(Rails) then Rails.env.to_s
|
62
|
-
end
|
68
|
+
return @options[:env] if @options.keys.include?(:env)
|
69
|
+
return Rails.env.to_s if defined?(Rails)
|
63
70
|
end
|
64
71
|
|
65
72
|
def deep_structify(hash)
|
66
|
-
|
67
|
-
hash.
|
68
|
-
result[key] = value.is_a?(Hash) ? deep_structify(value) : value
|
69
|
-
end if hash
|
73
|
+
hash ||= {}
|
74
|
+
result = Hash[hash.map { |k, v| [k, v.is_a?(Hash) ? deep_structify(v) : v] }]
|
70
75
|
OpenStruct.new(result)
|
71
76
|
end
|
72
77
|
|
@@ -77,15 +82,17 @@ module HasConfiguration #:nodoc:
|
|
77
82
|
end
|
78
83
|
|
79
84
|
def deep_stringified_hash
|
80
|
-
@deep_stringified_hash ||= deep_transform_keys(@hash
|
85
|
+
@deep_stringified_hash ||= deep_transform_keys(@hash, &:to_s)
|
81
86
|
end
|
82
87
|
|
83
88
|
# from Rails 4.0 (/active_support/core_ext/hash/keys.rb)
|
84
89
|
def deep_transform_keys(hash, &block)
|
85
90
|
result = {}
|
86
|
-
hash
|
87
|
-
|
88
|
-
|
91
|
+
if hash
|
92
|
+
hash.each do |key, value|
|
93
|
+
result[yield(key)] = value.is_a?(Hash) ? deep_transform_keys(value, &block) : value
|
94
|
+
end
|
95
|
+
end
|
89
96
|
result
|
90
97
|
end
|
91
98
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_configuration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Spickermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
113
|
requirements:
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
116
|
+
version: 2.1.0
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
119
|
- - ">="
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.6.8
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Simple configuration handling
|