has_configuration 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40f44c4cea757f02eefd7f88c4ebe57191f7fd66
4
- data.tar.gz: 8f43c0b7f09647f1b64a81bb087bb137340973ac
3
+ metadata.gz: 4e711006bd79831f88942f6a8f00c73adda21e06
4
+ data.tar.gz: cae116f13df37c98c094537f77528acb37f0c5bb
5
5
  SHA512:
6
- metadata.gz: 702a7f3bb8b1c8f8f369a66a07d1f2ae9979282fd8aa501a8885dfa58a377dd8169bc726e96151a953feb69a37b91d196edcd68adfa7ff09bc23122c9ad192b6
7
- data.tar.gz: 7e565b1b17efaa841c5fa15fa9f2377807df8b1b67a1c6ca1dadf94333fcbf73684234d56af5b3fe34fff860dd431c5005b72c9c9e68996ea69a964b1682cc5d
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
- private
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.load(ERB.new(raw_file(filename)).result)
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] if 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
- fail ArgumentError,
54
- 'Unable to resolve filename, please add :file parameter to has_configuration'
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
- case
60
- when @options.keys.include?(:env) then @options[:env]
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
- result = {}
67
- hash.each do |key, value|
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) { |key| key.to_s }
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.each do |key, value|
87
- result[yield(key)] = value.is_a?(Hash) ? deep_transform_keys(value, &block) : value
88
- end if hash
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
@@ -1,6 +1,6 @@
1
1
  module HasConfiguration #:nodoc:
2
2
  module VERSION #:nodoc:
3
- MAJOR = 1
3
+ MAJOR = 2
4
4
  MINOR = 0
5
5
  BUILD = 0
6
6
 
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: 1.0.0
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: 2015-04-07 00:00:00.000000000 Z
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: '0'
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.4.5
124
+ rubygems_version: 2.6.8
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Simple configuration handling