bogo-config 0.1.14 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -8
- data/bogo-config.gemspec +6 -4
- data/lib/bogo-config/config.rb +71 -24
- data/lib/bogo-config/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36cf589e82eeeeb0693171b9e54da8e828a17c1f
|
4
|
+
data.tar.gz: ea5083e9fe3e79cc4188700ee4d2da4c431e8925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fccfe868de90bc88f45a33ebbc69fbb483c2ed66ff4feeb4776bb59a2096772a793a855cf686984e6b6e09b12904c949260f624c5649732b97a708dbebad4be
|
7
|
+
data.tar.gz: 73cdc5bafdef588bd8c95825849de6e95395b14e4ccd04269cb70d7c459f41f42332f7d954a742d955769d2ecb5dd92c98911fdb034cf546bd3ffdef9950b959
|
data/CHANGELOG.md
CHANGED
@@ -1,29 +1,33 @@
|
|
1
|
-
|
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
|
-
|
8
|
+
# v0.1.12
|
5
9
|
* Allow Ruby config disable via environment variable
|
6
10
|
* Remove exclusive use during init
|
7
11
|
|
8
|
-
|
12
|
+
# v0.1.10
|
9
13
|
* Gracefully handle failures of ruby files (rescue parse errors)
|
10
14
|
|
11
|
-
|
15
|
+
# v0.1.8
|
12
16
|
* Support JSON serialization of configurations
|
13
17
|
|
14
|
-
|
18
|
+
# v0.1.6
|
15
19
|
* Remove dirty functionality to retain consistent data access
|
16
20
|
* Allow setting configuration as immutable
|
17
21
|
|
18
|
-
|
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
|
-
|
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
|
-
|
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.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.
|
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
|
data/lib/bogo-config/config.rb
CHANGED
@@ -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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
data/lib/bogo-config/version.rb
CHANGED
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.
|
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:
|
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.
|
138
|
+
rubygems_version: 2.5.1
|
111
139
|
signing_key:
|
112
140
|
specification_version: 4
|
113
141
|
summary: Configuration helper library
|