figleaf 0.3.0 → 0.4.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/.rspec +1 -1
- data/.solargraph.yml +16 -0
- data/CHANGELOG.md +19 -7
- data/lib/figleaf/config.rb +2 -13
- data/lib/figleaf/fighash.rb +2 -0
- data/lib/figleaf/lazy_block_hash.rb +16 -0
- data/lib/figleaf/settings.rb +28 -5
- data/lib/figleaf/version.rb +3 -1
- data/lib/figleaf.rb +4 -0
- data/spec/figleaf/config_spec.rb +2 -0
- data/spec/figleaf/configuration_spec.rb +19 -17
- data/spec/figleaf/fighash_spec.rb +6 -4
- data/spec/figleaf/settings_spec.rb +114 -12
- data/spec/fixtures/extra/default.yml +1 -1
- data/spec/fixtures/extra/default_anchor.yml +1 -1
- data/spec/fixtures/extra/merged_rb.rb +33 -0
- data/spec/fixtures/extra/merged_yaml.yaml +29 -0
- data/spec/fixtures/extra/regexp.rb +3 -0
- data/spec/fixtures/regexp.yml +2 -0
- data/spec/fixtures/type_errors/bad_overrides.yml +11 -0
- data/spec/fixtures/yaml.yaml +3 -0
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1b89f2110836d4dd5f0ad63b08f4a4ce2b8c6b17edbb1103a73e85ffaa898c9
|
4
|
+
data.tar.gz: b798a685d89f189e37e89624f08d8c2a6f9bce2abad278f983e83dee5cf292fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b00325b3a45103b5b3d9859befeff699bea806e981757b86371ada1cf933ebdb9a4e1cbb139ae96127b221543d1f6092441dfb3e591624f289ae2e0bac91cccd
|
7
|
+
data.tar.gz: 51f854f9551e34b2b5492113f027cad42ad8519c1f86be2ed8c05bf8dc6ae498360edc0bd2578971e428bf39325ebe62f67a4aec9d43d812ba70972f04e2cab4
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--format
|
2
|
+
--format documentation
|
data/.solargraph.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,28 +1,40 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.3.1 (2024/04/24)
|
4
|
+
|
5
|
+
- Allow loading regexps
|
6
|
+
|
3
7
|
## 0.3.0 (2024/04/05)
|
8
|
+
|
4
9
|
- Use YAML.safe_load to support versions of Psych >4
|
5
10
|
- Target modern rubies
|
6
11
|
- Take advantage of Ruby 3's single line methods
|
7
12
|
- Use standardrb to auto format all files
|
8
13
|
|
9
14
|
## 0.2.7, 0.2.8 and 0.2.9 (2017/09/28)
|
10
|
-
|
15
|
+
|
16
|
+
- Bugfixes
|
11
17
|
|
12
18
|
## 0.2.6 (2017/09/28)
|
13
|
-
|
19
|
+
|
20
|
+
- Add ability to write config files in ruby
|
14
21
|
|
15
22
|
## 0.2.5 (2017/09/28)
|
16
|
-
|
23
|
+
|
24
|
+
- Add support for `default` options
|
17
25
|
|
18
26
|
## 0.2.4 (2017/08/25)
|
19
|
-
|
27
|
+
|
28
|
+
- Relax active support version dependency
|
20
29
|
|
21
30
|
## 0.2.3 (2017/03/09)
|
22
|
-
|
31
|
+
|
32
|
+
- Include original error along with file that failed loading
|
23
33
|
|
24
34
|
## 0.2.2 (2017/03/08)
|
25
|
-
|
35
|
+
|
36
|
+
- Report what file failed loading on startup
|
26
37
|
|
27
38
|
## 0.2.1
|
28
|
-
|
39
|
+
|
40
|
+
- Fixes for rails 4
|
data/lib/figleaf/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Figleaf
|
2
4
|
# Convert a ruby block to nested hash
|
3
5
|
class Config
|
@@ -33,17 +35,4 @@ module Figleaf
|
|
33
35
|
|
34
36
|
attr_reader :property
|
35
37
|
end
|
36
|
-
|
37
|
-
class LazyBlockHash < Hash
|
38
|
-
def [](attr)
|
39
|
-
val = super(attr)
|
40
|
-
if val.is_a?(Proc)
|
41
|
-
val.call
|
42
|
-
else
|
43
|
-
val
|
44
|
-
end
|
45
|
-
rescue => e
|
46
|
-
raise Settings::InvalidRb, "Configuration has invalid Ruby\n" + e.message
|
47
|
-
end
|
48
|
-
end
|
49
38
|
end
|
data/lib/figleaf/fighash.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Figleaf
|
4
|
+
class LazyBlockHash < Hash
|
5
|
+
def [](attr)
|
6
|
+
val = super
|
7
|
+
if val.is_a?(Proc)
|
8
|
+
val.call
|
9
|
+
else
|
10
|
+
val
|
11
|
+
end
|
12
|
+
rescue => e
|
13
|
+
raise Settings::InvalidRb, "Configuration has invalid Ruby\n#{e.message}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/figleaf/settings.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Figleaf
|
2
4
|
class Settings
|
3
5
|
InvalidYAML = Class.new(RuntimeError)
|
4
6
|
InvalidRb = Class.new(RuntimeError)
|
7
|
+
MismatchedTypes = Class.new(RuntimeError)
|
5
8
|
|
6
9
|
class_attribute :auto_define
|
7
10
|
self.auto_define = false
|
@@ -58,11 +61,11 @@ module Figleaf
|
|
58
61
|
end
|
59
62
|
|
60
63
|
def load_file(file, env_to_load = env)
|
64
|
+
property_name = File.basename(file, ".*")
|
65
|
+
|
61
66
|
if file.end_with?(".rb")
|
62
|
-
property_name = File.basename(file, ".rb")
|
63
67
|
config = load_rb_file(file) or return nil
|
64
68
|
else
|
65
|
-
property_name = File.basename(file, ".yml")
|
66
69
|
config = load_yaml_file(file) or return nil
|
67
70
|
end
|
68
71
|
|
@@ -70,7 +73,23 @@ module Figleaf
|
|
70
73
|
|
71
74
|
default = config["default"]
|
72
75
|
property = config[env_to_load]
|
73
|
-
|
76
|
+
|
77
|
+
property =
|
78
|
+
if property.nil? && default.nil?
|
79
|
+
return nil
|
80
|
+
elsif property.nil?
|
81
|
+
default
|
82
|
+
elsif default.nil?
|
83
|
+
property
|
84
|
+
elsif default.class.name != property.class.name
|
85
|
+
raise MismatchedTypes, "Error loading file #{file}: mismatch between default values (type #{default.class.name}) and #{env_to_load} (type #{property.class.name})"
|
86
|
+
else
|
87
|
+
case default
|
88
|
+
when Hash then default.deep_merge(property)
|
89
|
+
when Array then default + property
|
90
|
+
else property
|
91
|
+
end
|
92
|
+
end
|
74
93
|
|
75
94
|
[property_name, use_hashie_if_hash(property)]
|
76
95
|
end
|
@@ -84,7 +103,7 @@ module Figleaf
|
|
84
103
|
end
|
85
104
|
|
86
105
|
def load_yaml_file(file_path)
|
87
|
-
YAML.safe_load(ERB.new(IO.read(file_path)).result, aliases: true)
|
106
|
+
YAML.safe_load(ERB.new(IO.read(file_path)).result, aliases: true, permitted_classes: [Regexp])
|
88
107
|
rescue Psych::SyntaxError => e
|
89
108
|
raise InvalidYAML, "#{file_path} has invalid YAML\n" + e.message
|
90
109
|
end
|
@@ -95,7 +114,11 @@ module Figleaf
|
|
95
114
|
end
|
96
115
|
|
97
116
|
def default_file_pattern
|
98
|
-
[
|
117
|
+
[
|
118
|
+
root.join("config", "settings", "*.yml"),
|
119
|
+
root.join("config", "settings", "*.yaml"),
|
120
|
+
root.join("config", "settings", "*.rb")
|
121
|
+
]
|
99
122
|
end
|
100
123
|
|
101
124
|
def env
|
data/lib/figleaf/version.rb
CHANGED
data/lib/figleaf.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/concern"
|
2
4
|
require "active_support/core_ext/class/attribute"
|
5
|
+
require "active_support/core_ext/hash"
|
3
6
|
require "active_support/core_ext/module/attribute_accessors"
|
4
7
|
require "active_support/core_ext/object/blank"
|
5
8
|
require "erb"
|
@@ -10,6 +13,7 @@ require "yaml"
|
|
10
13
|
module Figleaf
|
11
14
|
autoload :Config, "figleaf/config"
|
12
15
|
autoload :Fighash, "figleaf/fighash"
|
16
|
+
autoload :LazyBlockHash, "figleaf/lazy_block_hash"
|
13
17
|
autoload :Settings, "figleaf/settings"
|
14
18
|
autoload :VERSION, "figleaf/version"
|
15
19
|
end
|
data/spec/figleaf/config_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe Figleaf::Settings do
|
@@ -8,12 +10,12 @@ describe Figleaf::Settings do
|
|
8
10
|
end
|
9
11
|
it "should auto define methods and set initial value when setter used" do
|
10
12
|
described_class.fictional_feature_enabled = :on
|
11
|
-
described_class.fictional_feature_enabled.
|
13
|
+
expect(described_class.fictional_feature_enabled).to eq(:on)
|
12
14
|
end
|
13
15
|
|
14
16
|
it "should return result of proc when set as a proc" do
|
15
17
|
described_class.call_this_proc = -> { 3 }
|
16
|
-
described_class.call_this_proc.
|
18
|
+
expect(described_class.call_this_proc).to eq(3)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -25,15 +27,15 @@ describe Figleaf::Settings do
|
|
25
27
|
end
|
26
28
|
|
27
29
|
it "should not auto defined setters and getters" do
|
28
|
-
expect { described_class.undefined_setting = :raises_error }.to raise_error
|
29
|
-
expect { described_class.undefined_setting }.to raise_error
|
30
|
+
expect { described_class.undefined_setting = :raises_error }.to raise_error(NoMethodError)
|
31
|
+
expect { described_class.undefined_setting }.to raise_error(NoMethodError)
|
30
32
|
end
|
31
33
|
|
32
34
|
it "should set/get previous defined attributes" do
|
33
|
-
described_class.fictional_feature_enabled.
|
35
|
+
expect(described_class.fictional_feature_enabled).to eq(:on)
|
34
36
|
|
35
37
|
described_class.fictional_feature_enabled = :off
|
36
|
-
described_class.fictional_feature_enabled.
|
38
|
+
expect(described_class.fictional_feature_enabled).to eq(:off)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -45,8 +47,8 @@ describe Figleaf::Settings do
|
|
45
47
|
s.enable_fictional_activity_feed = true
|
46
48
|
end
|
47
49
|
|
48
|
-
described_class.another_fictional_feature_mode.
|
49
|
-
described_class.enable_fictional_activity_feed.
|
50
|
+
expect(described_class.another_fictional_feature_mode).to eq(:admin)
|
51
|
+
expect(described_class.enable_fictional_activity_feed).to be true
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
@@ -56,8 +58,8 @@ describe Figleaf::Settings do
|
|
56
58
|
s.some_boolean = true
|
57
59
|
end
|
58
60
|
|
59
|
-
described_class.some_boolean.
|
60
|
-
described_class.some_boolean
|
61
|
+
expect(described_class.some_boolean).to be true
|
62
|
+
expect(described_class.some_boolean?).to be true
|
61
63
|
end
|
62
64
|
|
63
65
|
it "should define predicate methods for false value" do
|
@@ -65,8 +67,8 @@ describe Figleaf::Settings do
|
|
65
67
|
s.another_boolean = false
|
66
68
|
end
|
67
69
|
|
68
|
-
described_class.another_boolean.
|
69
|
-
described_class.another_boolean
|
70
|
+
expect(described_class.another_boolean).to be false
|
71
|
+
expect(described_class.another_boolean?).to be false
|
70
72
|
end
|
71
73
|
|
72
74
|
it "should evaluate presence predicate methods for string value" do
|
@@ -74,7 +76,7 @@ describe Figleaf::Settings do
|
|
74
76
|
s.not_a_boolean = "Hello, world!"
|
75
77
|
end
|
76
78
|
|
77
|
-
described_class.not_a_boolean
|
79
|
+
expect(described_class.not_a_boolean?).to be true
|
78
80
|
end
|
79
81
|
|
80
82
|
it "should return false for empty string" do
|
@@ -82,7 +84,7 @@ describe Figleaf::Settings do
|
|
82
84
|
s.empty_string = ""
|
83
85
|
end
|
84
86
|
|
85
|
-
described_class.empty_string
|
87
|
+
expect(described_class.empty_string?).to be false
|
86
88
|
end
|
87
89
|
|
88
90
|
it "return true for lists" do
|
@@ -90,7 +92,7 @@ describe Figleaf::Settings do
|
|
90
92
|
s.not_a_boolean = %w[1 2 3]
|
91
93
|
end
|
92
94
|
|
93
|
-
described_class.not_a_boolean
|
95
|
+
expect(described_class.not_a_boolean?).to be true
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
@@ -105,7 +107,7 @@ describe Figleaf::Settings do
|
|
105
107
|
s.fictional_feature_enabled = :off
|
106
108
|
end
|
107
109
|
|
108
|
-
described_class.fictional_feature_enabled.
|
110
|
+
expect(described_class.fictional_feature_enabled).to eq(:off)
|
109
111
|
end
|
110
112
|
|
111
113
|
it "should only allow setting of values for previously defined attributes" do
|
@@ -113,7 +115,7 @@ describe Figleaf::Settings do
|
|
113
115
|
described_class.configure do |s|
|
114
116
|
s.undefined_setting = :should_raise_error
|
115
117
|
end
|
116
|
-
}.to raise_error
|
118
|
+
}.to raise_error(NoMethodError)
|
117
119
|
end
|
118
120
|
end
|
119
121
|
end
|
@@ -1,25 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe Figleaf::Fighash do
|
4
6
|
describe "#to_hash" do
|
5
7
|
it "should return class Hash" do
|
6
|
-
subject.to_hash.class.
|
8
|
+
expect(subject.to_hash.class).to eq(Hash)
|
7
9
|
end
|
8
10
|
|
9
11
|
context "should have symbols as keys" do
|
10
12
|
it "for symbol keys" do
|
11
13
|
subject = described_class.new({a: :b, c: 1, d: "foo"})
|
12
|
-
subject.to_hash.
|
14
|
+
expect(subject.to_hash).to eq({a: :b, c: 1, d: "foo"})
|
13
15
|
end
|
14
16
|
|
15
17
|
it "for string keys" do
|
16
18
|
subject = described_class.new({"a" => :b, "c" => 1, "d" => "foo"})
|
17
|
-
subject.to_hash.
|
19
|
+
expect(subject.to_hash).to eq({a: :b, c: 1, d: "foo"})
|
18
20
|
end
|
19
21
|
|
20
22
|
it "should have symbols as keys inside two levels" do
|
21
23
|
subject = described_class.new({a: {b: :d}})
|
22
|
-
subject.to_hash.
|
24
|
+
expect(subject.to_hash).to eq({a: {b: :d}})
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -1,12 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe Figleaf::Settings do
|
6
|
+
# Force a freshly loaded Figleaf::Settings class on every test run
|
7
|
+
before do
|
8
|
+
Figleaf.send(:remove_const, :Settings) if Figleaf.const_defined?(:Settings)
|
9
|
+
load "lib/figleaf/settings.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Force a new reference to the class
|
13
|
+
subject(:described_class) { Figleaf::Settings }
|
14
|
+
|
4
15
|
describe "self.load_settings" do
|
5
|
-
|
6
|
-
@fixtures_path = File.expand_path("../../fixtures/*.yml", __FILE__)
|
16
|
+
let(:fixtures_path) { File.expand_path("../../fixtures/*.yml", __FILE__) }
|
7
17
|
|
8
|
-
|
9
|
-
end
|
18
|
+
before { described_class.load_settings(fixtures_path, "test") }
|
10
19
|
|
11
20
|
it "load some service" do
|
12
21
|
expect(described_class.service["foo"]).to eq("bar")
|
@@ -42,7 +51,7 @@ describe Figleaf::Settings do
|
|
42
51
|
end
|
43
52
|
|
44
53
|
it "and for boolean (false)" do
|
45
|
-
described_class.load_settings(
|
54
|
+
described_class.load_settings(fixtures_path, "alt")
|
46
55
|
expect(described_class.boolean).to eq(false)
|
47
56
|
end
|
48
57
|
|
@@ -51,8 +60,12 @@ describe Figleaf::Settings do
|
|
51
60
|
expect(described_class.erb.bar).to be_nil
|
52
61
|
end
|
53
62
|
|
63
|
+
it "and for regexp values" do
|
64
|
+
expect(described_class.regexp.some_matcher).to eq(/\Amatcher\z/)
|
65
|
+
end
|
66
|
+
|
54
67
|
it "raise exception when loading an undefined value" do
|
55
|
-
YAML.
|
68
|
+
allow(YAML).to receive(:load_yaml_file).and_return({"test" => {}})
|
56
69
|
described_class.load_settings
|
57
70
|
expect { described_class.service.blah }.to raise_error NoMethodError
|
58
71
|
end
|
@@ -77,6 +90,29 @@ describe Figleaf::Settings do
|
|
77
90
|
end
|
78
91
|
end
|
79
92
|
|
93
|
+
context "incompatible types" do
|
94
|
+
context "bad overrides" do
|
95
|
+
subject(:settings) { described_class.bad_overrides }
|
96
|
+
|
97
|
+
let(:fixtures_path) { File.expand_path("../../fixtures/type_errors/bad_overrides.yml", __FILE__) }
|
98
|
+
|
99
|
+
it "raises an error when overloading a hash with an array" do
|
100
|
+
expect { described_class.load_settings(fixtures_path, "array") }
|
101
|
+
.to raise_error(described_class::MismatchedTypes)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "raises an error when overloading a hash with a string" do
|
105
|
+
expect { described_class.load_settings(fixtures_path, "string") }
|
106
|
+
.to raise_error(described_class::MismatchedTypes)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "raises an error when overloading a hash with a bool" do
|
110
|
+
expect { described_class.load_settings(fixtures_path, "bool") }
|
111
|
+
.to raise_error(described_class::MismatchedTypes)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
80
116
|
context "overloading settings" do
|
81
117
|
before do
|
82
118
|
overload = File.expand_path("../../fixtures/extra/*.yml", __FILE__)
|
@@ -106,7 +142,7 @@ describe Figleaf::Settings do
|
|
106
142
|
end
|
107
143
|
|
108
144
|
it "overrides values" do
|
109
|
-
expect(described_class.default.foo).to eq("
|
145
|
+
expect(described_class.default.foo).to eq("overridden")
|
110
146
|
end
|
111
147
|
|
112
148
|
it "respects values set in default" do
|
@@ -121,7 +157,7 @@ describe Figleaf::Settings do
|
|
121
157
|
end
|
122
158
|
|
123
159
|
it "overrides values" do
|
124
|
-
expect(described_class.default_anchor.foo).to eq("
|
160
|
+
expect(described_class.default_anchor.foo).to eq("overridden")
|
125
161
|
end
|
126
162
|
|
127
163
|
it "respects values set in default_anchor" do
|
@@ -130,12 +166,69 @@ describe Figleaf::Settings do
|
|
130
166
|
end
|
131
167
|
end
|
132
168
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
169
|
+
shared_examples_for "merged hashes" do
|
170
|
+
context "when using the default" do
|
171
|
+
before { described_class.load_settings(fixtures_path, "some_env") }
|
172
|
+
|
173
|
+
it "test a non overridden environment" do
|
174
|
+
expect(merged).to match(
|
175
|
+
"leaf1" => "default1",
|
176
|
+
"root1" => {"leaf11" => "default2"},
|
177
|
+
"root2" => {
|
178
|
+
"leaf21" => "default3",
|
179
|
+
"root21" => {
|
180
|
+
"leaf211" => "default4",
|
181
|
+
"root211" => {"leaf2111" => "default5"}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
)
|
185
|
+
end
|
137
186
|
end
|
138
187
|
|
188
|
+
context "with an overridden environment" do
|
189
|
+
before { described_class.load_settings(fixtures_path, "overridden") }
|
190
|
+
|
191
|
+
it "merges the values" do
|
192
|
+
expect(merged).to match(
|
193
|
+
"leaf1" => "default1",
|
194
|
+
"leaf2" => "overridden1",
|
195
|
+
"root1" => {"leaf11" => "overridden2"},
|
196
|
+
"root2" => {
|
197
|
+
"leaf21" => "default3",
|
198
|
+
"leaf22" => "overridden3",
|
199
|
+
"root21" => {
|
200
|
+
"leaf211" => "overridden4",
|
201
|
+
"root211" => {
|
202
|
+
"leaf2111" => "default5",
|
203
|
+
"leaf2112" => "overridden5"
|
204
|
+
}
|
205
|
+
}
|
206
|
+
}
|
207
|
+
)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "load yaml files" do
|
213
|
+
let(:fixtures_path) { File.expand_path("../../fixtures/**/*.yaml", __FILE__) }
|
214
|
+
|
215
|
+
before { described_class.load_settings(fixtures_path, "test") }
|
216
|
+
|
217
|
+
it "reads them just fine" do
|
218
|
+
expect(described_class.yaml.works).to eq("here")
|
219
|
+
end
|
220
|
+
|
221
|
+
context "hashes are merged" do
|
222
|
+
subject(:merged) { described_class.merged_yaml }
|
223
|
+
it_behaves_like "merged hashes"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "load ruby files" do
|
228
|
+
let(:fixtures_path) { File.expand_path("../../fixtures/extra/*.rb", __FILE__) }
|
229
|
+
|
230
|
+
before { described_class.load_settings(fixtures_path, "test") }
|
231
|
+
|
139
232
|
it "load indifferently the key names" do
|
140
233
|
expect(described_class.code["foo"]).to eq("bar")
|
141
234
|
expect(described_class.code[:foo]).to eq("bar")
|
@@ -169,5 +262,14 @@ describe Figleaf::Settings do
|
|
169
262
|
it "and for ENV values" do
|
170
263
|
expect(described_class.code.from_env).to eq("foo")
|
171
264
|
end
|
265
|
+
|
266
|
+
it "and for regexp values" do
|
267
|
+
expect(described_class.regexp.value).to eq(/\Amatcher\z/)
|
268
|
+
end
|
269
|
+
|
270
|
+
context "hashes are merged" do
|
271
|
+
subject(:merged) { described_class.merged_rb }
|
272
|
+
it_behaves_like "merged hashes"
|
273
|
+
end
|
172
274
|
end
|
173
275
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
default do
|
2
|
+
leaf1 "default1"
|
3
|
+
root1(leaf11: "default2")
|
4
|
+
root2(
|
5
|
+
leaf21: "default3",
|
6
|
+
root21: {
|
7
|
+
leaf211: "default4",
|
8
|
+
root211: {
|
9
|
+
leaf2111: "default5"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
unused do
|
16
|
+
root1(leaf11: "unused11")
|
17
|
+
root2(root21: {root21: {leaf211: "unused2"}})
|
18
|
+
end
|
19
|
+
|
20
|
+
overridden do
|
21
|
+
leaf2 "overridden1"
|
22
|
+
root1(leaf11: "overridden2")
|
23
|
+
|
24
|
+
root2(
|
25
|
+
leaf22: "overridden3",
|
26
|
+
root21: {
|
27
|
+
leaf211: "overridden4",
|
28
|
+
root211: {
|
29
|
+
leaf2112: "overridden5"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
)
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
---
|
2
|
+
default:
|
3
|
+
leaf1: default1
|
4
|
+
root1:
|
5
|
+
leaf11: default2
|
6
|
+
root2:
|
7
|
+
leaf21: default3
|
8
|
+
root21:
|
9
|
+
leaf211: default4
|
10
|
+
root211:
|
11
|
+
leaf2111: default5
|
12
|
+
|
13
|
+
unused:
|
14
|
+
root1:
|
15
|
+
leaf11: unused1
|
16
|
+
root2:
|
17
|
+
root21:
|
18
|
+
leaf211: unused2
|
19
|
+
|
20
|
+
overridden:
|
21
|
+
leaf2: overridden1
|
22
|
+
root1:
|
23
|
+
leaf11: overridden2
|
24
|
+
root2:
|
25
|
+
leaf22: overridden3
|
26
|
+
root21:
|
27
|
+
leaf211: overridden4
|
28
|
+
root211:
|
29
|
+
leaf2112: overridden5
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: figleaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan C. Müller
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -47,6 +46,7 @@ extra_rdoc_files: []
|
|
47
46
|
files:
|
48
47
|
- ".gitignore"
|
49
48
|
- ".rspec"
|
49
|
+
- ".solargraph.yml"
|
50
50
|
- ".travis.yml"
|
51
51
|
- CHANGELOG.md
|
52
52
|
- Gemfile
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/figleaf.rb
|
60
60
|
- lib/figleaf/config.rb
|
61
61
|
- lib/figleaf/fighash.rb
|
62
|
+
- lib/figleaf/lazy_block_hash.rb
|
62
63
|
- lib/figleaf/settings.rb
|
63
64
|
- lib/figleaf/version.rb
|
64
65
|
- spec/figleaf/config_spec.rb
|
@@ -75,14 +76,19 @@ files:
|
|
75
76
|
- spec/fixtures/extra/code.rb
|
76
77
|
- spec/fixtures/extra/default.yml
|
77
78
|
- spec/fixtures/extra/default_anchor.yml
|
79
|
+
- spec/fixtures/extra/merged_rb.rb
|
80
|
+
- spec/fixtures/extra/merged_yaml.yaml
|
81
|
+
- spec/fixtures/extra/regexp.rb
|
78
82
|
- spec/fixtures/extra/service.yml
|
83
|
+
- spec/fixtures/regexp.yml
|
79
84
|
- spec/fixtures/service.yml
|
80
85
|
- spec/fixtures/string.yml
|
86
|
+
- spec/fixtures/type_errors/bad_overrides.yml
|
87
|
+
- spec/fixtures/yaml.yaml
|
81
88
|
- spec/spec_helper.rb
|
82
89
|
homepage: http://github.com/jcmuller/figleaf
|
83
90
|
licenses: []
|
84
91
|
metadata: {}
|
85
|
-
post_install_message:
|
86
92
|
rdoc_options: []
|
87
93
|
require_paths:
|
88
94
|
- lib
|
@@ -97,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
103
|
- !ruby/object:Gem::Version
|
98
104
|
version: '0'
|
99
105
|
requirements: []
|
100
|
-
rubygems_version: 3.
|
101
|
-
signing_key:
|
106
|
+
rubygems_version: 3.7.1
|
102
107
|
specification_version: 4
|
103
108
|
summary: YAML based DRY settings manager.
|
104
109
|
test_files: []
|