bogo-config 0.1.14 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edc71f05269f56aeb9ca69209a4b90cc3e1e3bd8
4
- data.tar.gz: 7cc71fd964e5c6b6e4f3b37fb6566f20be6e75bb
3
+ metadata.gz: 36cf589e82eeeeb0693171b9e54da8e828a17c1f
4
+ data.tar.gz: ea5083e9fe3e79cc4188700ee4d2da4c431e8925
5
5
  SHA512:
6
- metadata.gz: be2e2a898f765199cfd55c1f647435af416fad82325b821579f270cb910265f77c62d93707f7ecc77337b0a1e17abbdb2d3203fe5a4aab9f0e9cc1dcd2693103
7
- data.tar.gz: fa88c6c0b25c37261dc37277b8f4cfceb150b037993c6c76f8a4a422710092d743e719aeb0cb125462180d3d59b66aeb33987e6d8b5bb33e9dc55cfba4bae8fd
6
+ metadata.gz: 3fccfe868de90bc88f45a33ebbc69fbb483c2ed66ff4feeb4776bb59a2096772a793a855cf686984e6b6e09b12904c949260f624c5649732b97a708dbebad4be
7
+ data.tar.gz: 73cdc5bafdef588bd8c95825849de6e95395b14e4ccd04269cb70d7c459f41f42332f7d954a742d955769d2ecb5dd92c98911fdb034cf546bd3ffdef9950b959
data/CHANGELOG.md CHANGED
@@ -1,29 +1,33 @@
1
- ## v0.1.14
1
+ # v0.2.0
2
+ * Stop configuration detection after successful load
3
+ * Use custom exception type for config load failures
4
+
5
+ # v0.1.14
2
6
  * Update debug environment variable name
3
7
 
4
- ## v0.1.12
8
+ # v0.1.12
5
9
  * Allow Ruby config disable via environment variable
6
10
  * Remove exclusive use during init
7
11
 
8
- ## v0.1.10
12
+ # v0.1.10
9
13
  * Gracefully handle failures of ruby files (rescue parse errors)
10
14
 
11
- ## v0.1.8
15
+ # v0.1.8
12
16
  * Support JSON serialization of configurations
13
17
 
14
- ## v0.1.6
18
+ # v0.1.6
15
19
  * Remove dirty functionality to retain consistent data access
16
20
  * Allow setting configuration as immutable
17
21
 
18
- ## v0.1.4
22
+ # v0.1.4
19
23
  * Delegate more methods from config instance to underlying data instance
20
24
  * Add initial support for auto reloading configuration
21
25
 
22
- ## v0.1.2
26
+ # v0.1.2
23
27
  * Update `Bogo::Config` to behave more like `Smash`
24
28
  * Make XML usage more consistent and apply type formats
25
29
  * Add `Configuration` class for cleaner struct usage
26
30
  * Add test coverage
27
31
 
28
- ## v0.1.0
32
+ # v0.1.0
29
33
  * Initial release
data/bogo-config.gemspec CHANGED
@@ -10,9 +10,11 @@ Gem::Specification.new do |s|
10
10
  s.description = 'Configuration helper library'
11
11
  s.require_path = 'lib'
12
12
  s.license = 'Apache 2.0'
13
- s.add_dependency 'bogo', '>= 0.1.4', '< 1.0'
14
- s.add_dependency 'multi_json'
15
- s.add_dependency 'multi_xml'
16
- s.add_dependency 'attribute_struct'
13
+ s.add_runtime_dependency 'bogo', '>= 0.1.4', '< 1.0'
14
+ s.add_runtime_dependency 'multi_json'
15
+ s.add_runtime_dependency 'multi_xml'
16
+ s.add_runtime_dependency 'attribute_struct'
17
+ s.add_development_dependency 'minitest'
18
+ s.add_development_dependency 'rake', '~> 10'
17
19
  s.files = Dir['lib/**/*'] + %w(bogo-config.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
18
20
  end
@@ -10,6 +10,24 @@ module Bogo
10
10
 
11
11
  class Config
12
12
 
13
+ # Exception wrapper class used for configuration file load failure
14
+ class FileLoadError < LoadError
15
+
16
+ # @return [Exception]
17
+ attr_reader :original
18
+
19
+ def initialize(message, original_exception = nil)
20
+ super(message)
21
+ @original = original_exception
22
+ end
23
+
24
+ # @return [Fixnum]
25
+ def exit_code
26
+ 222
27
+ end
28
+
29
+ end
30
+
13
31
  class << self
14
32
 
15
33
  include Bogo::Memoization
@@ -170,31 +188,42 @@ module Bogo
170
188
  # @param file_path [String] path to file
171
189
  # @return [Smash]
172
190
  def load_file(file_path)
173
- case File.extname(file_path)
174
- when '.yaml', '.yml'
175
- yaml_load(file_path)
176
- when '.json'
177
- json_load(file_path)
178
- when '.xml'
179
- xml_load(file_path)
180
- when '.rb' && eval_enabled?
181
- struct_load(file_path)
182
- else
183
- result = [:struct_load, :json_load, :yaml_load, :xml_load].map do |loader|
184
- begin
185
- send(loader, file_path)
186
- rescue StandardError, ScriptError => e
187
- if(ENV['BOGO_DEBUG'])
188
- $stderr.puts "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
189
- end
190
- nil
191
- end
192
- end.compact.first
193
- unless(result)
194
- raise "Failed to load configuration from file (#{file_path})"
195
- end
196
- result
191
+ result = nil
192
+ errors = Smash.new
193
+ error = nil
194
+ begin
195
+ result = case File.extname(file_path)
196
+ when '.yaml', '.yml'
197
+ yaml_load(file_path)
198
+ when '.json'
199
+ json_load(file_path)
200
+ when '.xml'
201
+ xml_load(file_path)
202
+ when '.rb' && eval_enabled?
203
+ struct_load(file_path)
204
+ else
205
+ [:struct_load, :json_load, :yaml_load, :xml_load].each do |loader|
206
+ begin
207
+ result = send(loader, file_path)
208
+ break
209
+ rescue StandardError, ScriptError => e
210
+ errors[loader] = e
211
+ if(ENV['BOGO_DEBUG'])
212
+ $stderr.puts "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
213
+ end
214
+ end
215
+ end
216
+ result
217
+ end
218
+ rescue => error
197
219
  end
220
+ unless(result)
221
+ raise FileLoadError.new(
222
+ "Failed to load configuration from file (#{file_path})",
223
+ error || extract_error_for(file_path, errors)
224
+ )
225
+ end
226
+ result
198
227
  end
199
228
 
200
229
  # Read and parse YAML file
@@ -282,5 +311,23 @@ module Bogo
282
311
  !eval_enabled?
283
312
  end
284
313
 
314
+ # Extract appropriate execption based on path
315
+ #
316
+ # @param path [String]
317
+ # @param errors [Hash]
318
+ # @return [Exception, NilClass]
319
+ def extract_error_for(path, errors)
320
+ content = File.read(path).strip
321
+ if(content.start_with?('{'))
322
+ errors[:json_load]
323
+ elsif(content.start_with?('<'))
324
+ errors[:xml_load]
325
+ elsif(content.match(/\.new\s*(do|\{)/))
326
+ errors[:struct_load]
327
+ else
328
+ errors[:yaml_load]
329
+ end
330
+ end
331
+
285
332
  end
286
333
  end
@@ -1,6 +1,6 @@
1
1
  module Bogo
2
2
  class Config
3
3
  # Current library version
4
- VERSION = Gem::Version.new('0.1.14')
4
+ VERSION = Gem::Version.new('0.2.0')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bogo-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-29 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo
@@ -72,6 +72,34 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: minitest
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '10'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '10'
75
103
  description: Configuration helper library
76
104
  email: code@chrisroberts.org
77
105
  executables: []
@@ -107,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
135
  version: '0'
108
136
  requirements: []
109
137
  rubyforge_project:
110
- rubygems_version: 2.4.8
138
+ rubygems_version: 2.5.1
111
139
  signing_key:
112
140
  specification_version: 4
113
141
  summary: Configuration helper library