complex_config 0.0.0 → 0.1.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/Gemfile +2 -0
- data/README.md +3 -0
- data/TODO.md +5 -0
- data/VERSION +1 -1
- data/complex_config.gemspec +4 -4
- data/lib/complex_config/provider.rb +11 -2
- data/lib/complex_config/settings.rb +7 -0
- data/lib/complex_config/version.rb +1 -1
- data/spec/complex_config/provider_spec.rb +19 -4
- data/spec/complex_config/settings_spec.rb +3 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be1bf6c1cc5c0472312df63b9f4e9b5d2165b659
|
4
|
+
data.tar.gz: 9234cf89ba86ed15fdc24041000ee334340d3ccf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47801efebe328219554dff8380be0db7098f430d2f913b461999fae3513f01ecab0a67300060222311a8cb0abc0e2c3d81e3017cb289f8d87b28b571f1a8eff6
|
7
|
+
data.tar.gz: 32a4b840c5ff2ab5a89a00b972f3efdf295bfb0cc4d2dec41bd6731d6595956036bec2a1e82af7b27ae490f89ceb4da815600afaf9b188e0a69261447b974bd2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/TODO.md
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.0
|
data/complex_config.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: complex_config 0.
|
2
|
+
# stub: complex_config 0.1.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "complex_config"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.1.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Florian Frank"]
|
11
|
-
s.date = "2014-12-
|
11
|
+
s.date = "2014-12-15"
|
12
12
|
s.description = "This library allows you to access configuration files via a simple interface"
|
13
13
|
s.email = "flori@ping.de"
|
14
14
|
s.extra_rdoc_files = ["README.md", "lib/complex_config.rb", "lib/complex_config/errors.rb", "lib/complex_config/plugins.rb", "lib/complex_config/plugins/enable.rb", "lib/complex_config/plugins/money.rb", "lib/complex_config/plugins/uri.rb", "lib/complex_config/provider.rb", "lib/complex_config/rude.rb", "lib/complex_config/settings.rb", "lib/complex_config/shortcuts.rb", "lib/complex_config/version.rb"]
|
15
|
-
s.files = [".gitignore", ".rspec", ".travis.yml", ".utilsrc", "Gemfile", "README.md", "Rakefile", "VERSION", "complex_config.gemspec", "lib/complex_config.rb", "lib/complex_config/errors.rb", "lib/complex_config/plugins.rb", "lib/complex_config/plugins/enable.rb", "lib/complex_config/plugins/money.rb", "lib/complex_config/plugins/uri.rb", "lib/complex_config/provider.rb", "lib/complex_config/rude.rb", "lib/complex_config/settings.rb", "lib/complex_config/shortcuts.rb", "lib/complex_config/version.rb", "spec/complex_config/plugins_spec.rb", "spec/complex_config/provider_spec.rb", "spec/complex_config/settings_spec.rb", "spec/complex_config/shortcuts_spec.rb", "spec/config/broken_config.yml", "spec/config/config.yml", "spec/spec_helper.rb"]
|
15
|
+
s.files = [".gitignore", ".rspec", ".travis.yml", ".utilsrc", "Gemfile", "README.md", "Rakefile", "TODO.md", "VERSION", "complex_config.gemspec", "lib/complex_config.rb", "lib/complex_config/errors.rb", "lib/complex_config/plugins.rb", "lib/complex_config/plugins/enable.rb", "lib/complex_config/plugins/money.rb", "lib/complex_config/plugins/uri.rb", "lib/complex_config/provider.rb", "lib/complex_config/rude.rb", "lib/complex_config/settings.rb", "lib/complex_config/shortcuts.rb", "lib/complex_config/version.rb", "spec/complex_config/plugins_spec.rb", "spec/complex_config/provider_spec.rb", "spec/complex_config/settings_spec.rb", "spec/complex_config/shortcuts_spec.rb", "spec/config/broken_config.yml", "spec/config/config.yml", "spec/spec_helper.rb"]
|
16
16
|
s.homepage = "https://github.com/flori/complex_config"
|
17
17
|
s.licenses = ["Apache-2.0"]
|
18
18
|
s.rdoc_options = ["--title", "ComplexConfig -- configuration library", "--main", "README.md"]
|
@@ -7,7 +7,8 @@ class ComplexConfig::Provider
|
|
7
7
|
include Tins::SexySingleton
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
@plugins
|
10
|
+
@plugins = Set.new
|
11
|
+
@deep_freeze = true
|
11
12
|
end
|
12
13
|
|
13
14
|
attr_reader :plugins
|
@@ -17,6 +18,12 @@ class ComplexConfig::Provider
|
|
17
18
|
self
|
18
19
|
end
|
19
20
|
|
21
|
+
attr_writer :deep_freeze
|
22
|
+
|
23
|
+
def deep_freeze?
|
24
|
+
!!@deep_freeze
|
25
|
+
end
|
26
|
+
|
20
27
|
def apply_plugins(setting, id)
|
21
28
|
@plugins.find do |plugin|
|
22
29
|
catch :skip do
|
@@ -32,7 +39,9 @@ class ComplexConfig::Provider
|
|
32
39
|
|
33
40
|
def config(pathname)
|
34
41
|
result = evaluate(pathname)
|
35
|
-
ComplexConfig::Settings[::YAML.load(result, pathname)]
|
42
|
+
ComplexConfig::Settings[::YAML.load(result, pathname)].tap do |settings|
|
43
|
+
deep_freeze? and settings.deep_freeze
|
44
|
+
end
|
36
45
|
rescue ::Errno::ENOENT => e
|
37
46
|
raise ComplexConfig::ComplexConfigError.wrap(:ConfigurationFileMissing, e)
|
38
47
|
rescue ::Psych::SyntaxError => e
|
@@ -35,6 +35,13 @@ class ComplexConfig::Settings < JSON::GenericObject
|
|
35
35
|
|
36
36
|
alias inspect to_s
|
37
37
|
|
38
|
+
def deep_freeze
|
39
|
+
each do |_, v|
|
40
|
+
v.ask_and_send(:deep_freeze) || (v.freeze rescue v)
|
41
|
+
end
|
42
|
+
freeze
|
43
|
+
end
|
44
|
+
|
38
45
|
private
|
39
46
|
|
40
47
|
def respond_to_missing?(id, include_private = false)
|
@@ -5,6 +5,10 @@ RSpec.describe ComplexConfig::Provider do
|
|
5
5
|
ComplexConfig::Provider
|
6
6
|
end
|
7
7
|
|
8
|
+
after do
|
9
|
+
provider.flush_cache
|
10
|
+
end
|
11
|
+
|
8
12
|
context 'plugin' do
|
9
13
|
let :plugin do
|
10
14
|
-> id { __send__ id }
|
@@ -62,6 +66,21 @@ RSpec.describe ComplexConfig::Provider do
|
|
62
66
|
).to be_a ComplexConfig::Settings
|
63
67
|
end
|
64
68
|
|
69
|
+
it 'has deep frozen settings' do
|
70
|
+
settings = provider.config(asset('config.yml'))
|
71
|
+
expect(settings).to be_frozen
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'deep freezing can be disabled' do
|
75
|
+
begin
|
76
|
+
provider.deep_freeze = false
|
77
|
+
settings = provider.config(asset('config.yml'))
|
78
|
+
expect(settings).not_to be_frozen
|
79
|
+
ensure
|
80
|
+
provider.deep_freeze = true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
65
84
|
it 'handles missing configuration files' do
|
66
85
|
expect { provider.config(asset('nix_config.yml')) }.to\
|
67
86
|
raise_error(ComplexConfig::ConfigurationFileMissing)
|
@@ -78,10 +97,6 @@ RSpec.describe ComplexConfig::Provider do
|
|
78
97
|
provider.root = Pathname.new(__FILE__).dirname.dirname
|
79
98
|
end
|
80
99
|
|
81
|
-
after do
|
82
|
-
provider.flush_cache
|
83
|
-
end
|
84
|
-
|
85
100
|
it 'returns the correct configuration' do
|
86
101
|
expect(provider['config']).to be_a ComplexConfig::Settings
|
87
102
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe ComplexConfig::Settings do
|
4
|
-
let :provider do
|
5
|
-
ComplexConfig::Provider
|
6
|
-
end
|
7
|
-
|
8
4
|
let :settings do
|
9
5
|
ComplexConfig::Settings[
|
10
6
|
foo: {
|
@@ -44,15 +40,15 @@ RSpec.describe ComplexConfig::Settings do
|
|
44
40
|
EOT
|
45
41
|
end
|
46
42
|
it 'raises exception if expected attribute is missing' do
|
47
|
-
|
48
|
-
expect { settings.
|
43
|
+
pending "still doesn't work"
|
44
|
+
expect { settings.nix }.to raise_error(ComplexConfig::AttributeMissing)
|
49
45
|
end
|
50
46
|
|
51
47
|
it 'can be checked for set attributes' do
|
52
48
|
expect(settings.foo.attribute_set?(:bar)).to eq true
|
53
49
|
expect(settings.foo.bar?).to be_truthy
|
54
50
|
expect(settings.foo.attribute_set?(:baz)).to eq false
|
55
|
-
#
|
51
|
+
#expect(settings.foo.baz?).to be_falsy
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: complex_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- Gemfile
|
134
134
|
- README.md
|
135
135
|
- Rakefile
|
136
|
+
- TODO.md
|
136
137
|
- VERSION
|
137
138
|
- complex_config.gemspec
|
138
139
|
- lib/complex_config.rb
|