rsettings 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +10 -10
- data/Gemfile +10 -10
- data/Gemfile.lock +67 -65
- data/LICENSE.txt +20 -20
- data/README.md +6 -6
- data/Rakefile +34 -34
- data/VERSION +1 -1
- data/lib/rsettings/adapters/basic_disk_settings.rb +51 -51
- data/lib/rsettings/adapters/environment_settings.rb +14 -14
- data/lib/rsettings/core/internal/defaults.rb +20 -20
- data/lib/rsettings/core/internal/settings_chain.rb +18 -18
- data/lib/rsettings/core/internal/settings_configuration.rb +41 -41
- data/lib/rsettings/core/missing.rb +15 -15
- data/lib/rsettings/core/names.rb +21 -21
- data/lib/rsettings/core/rsettings.rb +29 -29
- data/lib/rsettings/core/setting.rb +16 -12
- data/lib/rsettings/core/setting_name.rb +15 -15
- data/lib/rsettings.rb +46 -46
- data/rsettings.gemspec +79 -77
- data/spec/integration.tests/adapters/basic_disk_settings_spec.rb +46 -46
- data/spec/spec_helper.rb +2 -2
- data/spec/system.tests/can_fall_back_to_file_settings_spec.rb +56 -56
- data/spec/system.tests/can_provide_translations_spec.rb +52 -0
- data/spec/system.tests/can_specify_flags_spec.rb +39 -31
- data/spec/system.tests/can_supply_defaults_for_missing_settings_spec.rb +39 -39
- data/spec/system.tests/can_use_env_spec.rb +37 -74
- data/spec/system.tests/options_spec.rb +18 -18
- metadata +10 -22
data/lib/rsettings/core/names.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
class Names
|
2
|
-
require "audible"; include Audible
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
@opts = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def add(opts={})
|
9
|
-
notify :adding, opts
|
10
|
-
@opts.merge!(opts.invert)
|
11
|
-
end
|
12
|
-
|
13
|
-
def for(setting)
|
14
|
-
notify :finding, setting
|
15
|
-
@opts[setting.to_s] || @opts[setting.to_sym] || setting
|
16
|
-
end
|
17
|
-
|
18
|
-
def reverse_for(name)
|
19
|
-
@opts.invert[name.value] || name.value
|
20
|
-
end
|
21
|
-
end
|
1
|
+
class Names
|
2
|
+
require "audible"; include Audible
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@opts = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(opts={})
|
9
|
+
notify :adding, opts
|
10
|
+
@opts.merge!(opts.invert)
|
11
|
+
end
|
12
|
+
|
13
|
+
def for(setting)
|
14
|
+
notify :finding, setting
|
15
|
+
@opts[setting.to_s] || @opts[setting.to_sym] || setting
|
16
|
+
end
|
17
|
+
|
18
|
+
def reverse_for(name)
|
19
|
+
@opts.invert[name.value] || name.value
|
20
|
+
end
|
21
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
class RSettings
|
2
|
-
require "audible"; include Audible
|
3
|
-
|
4
|
-
def initialize(opts={})
|
5
|
-
@settings,@names = opts[:settings],opts[:names]
|
6
|
-
end
|
7
|
-
|
8
|
-
def find(m)
|
9
|
-
query = m.to_s.end_with? "?"
|
10
|
-
|
11
|
-
m = m.to_s.delete "?" if query
|
12
|
-
|
13
|
-
name = ConvertibleSettingName.new(@names, m)
|
14
|
-
|
15
|
-
if query
|
16
|
-
value = @settings.get(name)
|
17
|
-
|
18
|
-
fail "Unable to convert setting <#{name.value}> to flag" unless value.truthy?
|
19
|
-
|
20
|
-
return value.
|
21
|
-
end
|
22
|
-
|
23
|
-
notify :finding, m, name
|
24
|
-
|
25
|
-
result = @settings.get(name)
|
26
|
-
|
27
|
-
result.missing? ? nil : result.to_s
|
28
|
-
end
|
29
|
-
end
|
1
|
+
class RSettings
|
2
|
+
require "audible"; include Audible
|
3
|
+
|
4
|
+
def initialize(opts={})
|
5
|
+
@settings,@names = opts[:settings],opts[:names]
|
6
|
+
end
|
7
|
+
|
8
|
+
def find(m)
|
9
|
+
query = m.to_s.end_with? "?"
|
10
|
+
|
11
|
+
m = m.to_s.delete "?" if query
|
12
|
+
|
13
|
+
name = ConvertibleSettingName.new(@names, m)
|
14
|
+
|
15
|
+
if query
|
16
|
+
value = @settings.get(name)
|
17
|
+
|
18
|
+
fail "Unable to convert setting <#{name.value}> to flag" unless value.truthy?
|
19
|
+
|
20
|
+
return value.true?
|
21
|
+
end
|
22
|
+
|
23
|
+
notify :finding, m, name
|
24
|
+
|
25
|
+
result = @settings.get(name)
|
26
|
+
|
27
|
+
result.missing? ? nil : result.to_s
|
28
|
+
end
|
29
|
+
end
|
@@ -1,12 +1,16 @@
|
|
1
|
-
class Setting
|
2
|
-
def truthy?; @truthy; end
|
3
|
-
|
4
|
-
def initialize(text="")
|
5
|
-
@text = text
|
6
|
-
@truthy = (text||"").downcase.match /(yes|no)/
|
7
|
-
end
|
8
|
-
|
9
|
-
def missing?; @text.nil?; end
|
10
|
-
|
11
|
-
def to_s; @text.to_s; end
|
12
|
-
|
1
|
+
class Setting
|
2
|
+
def truthy?; @truthy; end
|
3
|
+
|
4
|
+
def initialize(text="")
|
5
|
+
@text = text
|
6
|
+
@truthy = (text||"").downcase.match /(yes|no|on|off)/
|
7
|
+
end
|
8
|
+
|
9
|
+
def missing?; @text.nil?; end
|
10
|
+
|
11
|
+
def to_s; @text.to_s; end
|
12
|
+
|
13
|
+
def true?
|
14
|
+
(@text||"").downcase.match /(yes|on)/
|
15
|
+
end
|
16
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
class SettingName
|
2
|
-
attr_reader :value
|
3
|
-
|
4
|
-
def initialize(name)
|
5
|
-
@value = name
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class ConvertibleSettingName
|
10
|
-
def initialize(names, name)
|
11
|
-
@name,@names = name,names
|
12
|
-
end
|
13
|
-
|
14
|
-
def value; @names.for @name; end
|
15
|
-
end
|
1
|
+
class SettingName
|
2
|
+
attr_reader :value
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
@value = name
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ConvertibleSettingName
|
10
|
+
def initialize(names, name)
|
11
|
+
@name,@names = name,names
|
12
|
+
end
|
13
|
+
|
14
|
+
def value; @names.for @name; end
|
15
|
+
end
|
data/lib/rsettings.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
dir = File.join(File.dirname(__FILE__))
|
2
|
-
|
3
|
-
Dir.glob(File.join(dir, "rsettings", "**", "*.rb")).each {|f| require f}
|
4
|
-
|
5
|
-
class Settings
|
6
|
-
def initialize(&block)
|
7
|
-
@conf = SettingsConfiguration.new &block
|
8
|
-
end
|
9
|
-
|
10
|
-
def method_missing(m, *args, &block)
|
11
|
-
fail "Only support queries, cannot do command <#{m}>" unless args.empty?
|
12
|
-
|
13
|
-
rsettings = RSettings.new(
|
14
|
-
:settings => @conf.settings,
|
15
|
-
:names => @conf.names
|
16
|
-
)
|
17
|
-
|
18
|
-
Probe.new rsettings
|
19
|
-
|
20
|
-
rsettings.find m
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Probe
|
25
|
-
def initialize(names)
|
26
|
-
names.on :finding do |e,args|
|
27
|
-
Log.info "[RSettings] Finding setting for <#{args.first}> by name <#{args[1].value}>"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class ConsoleLog
|
33
|
-
class << self
|
34
|
-
def info(what)
|
35
|
-
puts "[INFO] #{what}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class DevNullLog
|
41
|
-
class << self
|
42
|
-
def info(what); end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
Log = ENV["LOUD"] == "on" ? ConsoleLog : DevNullLog
|
1
|
+
dir = File.join(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
Dir.glob(File.join(dir, "rsettings", "**", "*.rb")).each {|f| require f}
|
4
|
+
|
5
|
+
class Settings
|
6
|
+
def initialize(&block)
|
7
|
+
@conf = SettingsConfiguration.new &block
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(m, *args, &block)
|
11
|
+
fail "Only support queries, cannot do command <#{m}>" unless args.empty?
|
12
|
+
|
13
|
+
rsettings = RSettings.new(
|
14
|
+
:settings => @conf.settings,
|
15
|
+
:names => @conf.names
|
16
|
+
)
|
17
|
+
|
18
|
+
Probe.new rsettings
|
19
|
+
|
20
|
+
rsettings.find m
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Probe
|
25
|
+
def initialize(names)
|
26
|
+
names.on :finding do |e,args|
|
27
|
+
Log.info "[RSettings] Finding setting for <#{args.first}> by name <#{args[1].value}>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class ConsoleLog
|
33
|
+
class << self
|
34
|
+
def info(what)
|
35
|
+
puts "[INFO] #{what}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class DevNullLog
|
41
|
+
class << self
|
42
|
+
def info(what); end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Log = ENV["LOUD"] == "on" ? ConsoleLog : DevNullLog
|
data/rsettings.gemspec
CHANGED
@@ -1,77 +1,79 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
s.
|
9
|
-
|
10
|
-
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
|
17
|
-
"
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
"
|
22
|
-
"Gemfile
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"lib/rsettings
|
29
|
-
"lib/rsettings/adapters/
|
30
|
-
"lib/rsettings/
|
31
|
-
"lib/rsettings/core/internal/
|
32
|
-
"lib/rsettings/core/internal/
|
33
|
-
"lib/rsettings/core/
|
34
|
-
"lib/rsettings/core/
|
35
|
-
"lib/rsettings/core/
|
36
|
-
"lib/rsettings/core/
|
37
|
-
"lib/rsettings/core/
|
38
|
-
"rsettings.
|
39
|
-
"
|
40
|
-
"spec/
|
41
|
-
"spec/
|
42
|
-
"spec/system.tests/
|
43
|
-
"spec/system.tests/
|
44
|
-
"spec/system.tests/
|
45
|
-
"spec/system.tests/
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
s.
|
50
|
-
s.
|
51
|
-
s.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
s.
|
60
|
-
s.add_development_dependency(%q<
|
61
|
-
s.add_development_dependency(%q<
|
62
|
-
|
63
|
-
s.
|
64
|
-
|
65
|
-
s.add_dependency(%q<
|
66
|
-
s.add_dependency(%q<
|
67
|
-
s.add_dependency(%q<
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
s.add_dependency(%q<
|
73
|
-
s.add_dependency(%q<
|
74
|
-
s.add_dependency(%q<
|
75
|
-
|
76
|
-
|
77
|
-
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: rsettings 0.5.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "rsettings"
|
9
|
+
s.version = "0.5.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ["Ben Biddington"]
|
13
|
+
s.date = "2013-12-23"
|
14
|
+
s.description = "Settings"
|
15
|
+
s.email = "ben.biddington@gmail.com"
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".travis.yml",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/rsettings.rb",
|
29
|
+
"lib/rsettings/adapters/basic_disk_settings.rb",
|
30
|
+
"lib/rsettings/adapters/environment_settings.rb",
|
31
|
+
"lib/rsettings/core/internal/defaults.rb",
|
32
|
+
"lib/rsettings/core/internal/settings_chain.rb",
|
33
|
+
"lib/rsettings/core/internal/settings_configuration.rb",
|
34
|
+
"lib/rsettings/core/missing.rb",
|
35
|
+
"lib/rsettings/core/names.rb",
|
36
|
+
"lib/rsettings/core/rsettings.rb",
|
37
|
+
"lib/rsettings/core/setting.rb",
|
38
|
+
"lib/rsettings/core/setting_name.rb",
|
39
|
+
"rsettings.gemspec",
|
40
|
+
"spec/integration.tests/adapters/basic_disk_settings_spec.rb",
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/system.tests/can_fall_back_to_file_settings_spec.rb",
|
43
|
+
"spec/system.tests/can_provide_translations_spec.rb",
|
44
|
+
"spec/system.tests/can_specify_flags_spec.rb",
|
45
|
+
"spec/system.tests/can_supply_defaults_for_missing_settings_spec.rb",
|
46
|
+
"spec/system.tests/can_use_env_spec.rb",
|
47
|
+
"spec/system.tests/options_spec.rb"
|
48
|
+
]
|
49
|
+
s.homepage = "http://github.com/ben-biddington/rsettings"
|
50
|
+
s.licenses = ["MIT"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = "2.1.11"
|
53
|
+
s.summary = "Settings for ruby programs"
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
s.specification_version = 4
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_runtime_dependency(%q<audible>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<audible>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
67
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
68
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<audible>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
75
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -1,46 +1,46 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe BasicDiskSettings do
|
4
|
-
let(:settings) {BasicDiskSettings.new}
|
5
|
-
|
6
|
-
before do
|
7
|
-
settings.clear
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:a) { SettingName.new :a}
|
11
|
-
let(:b) { SettingName.new :b}
|
12
|
-
|
13
|
-
it "can store single setting" do
|
14
|
-
settings.set :a => "value"
|
15
|
-
|
16
|
-
expect(settings.get(a).to_s).to eql "value"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "can store multiple settings at once" do
|
20
|
-
settings.set :a => "value a", :b => "value b"
|
21
|
-
|
22
|
-
expect(settings.get(a).to_s).to eql "value a"
|
23
|
-
expect(settings.get(b).to_s).to eql "value b"
|
24
|
-
end
|
25
|
-
|
26
|
-
it "overwrites duplicates" do
|
27
|
-
settings.set :a => "value a"
|
28
|
-
settings.set :a => "another value for a"
|
29
|
-
|
30
|
-
expect(settings.get(a).to_s).to eql "another value for a"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "overwrites duplicates even when setting the same setting" do
|
34
|
-
settings.set :a => "value a", :a => "another value for a"
|
35
|
-
|
36
|
-
expect(settings.get(a).to_s).to eql "another value for a"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "records all settings when you call set multiple times" do
|
40
|
-
settings.set :a => "value a"
|
41
|
-
settings.set :b => "value b"
|
42
|
-
|
43
|
-
expect(settings.get(a).to_s).to_not be_nil
|
44
|
-
expect(settings.get(b).to_s).to_not be_nil
|
45
|
-
end
|
46
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BasicDiskSettings do
|
4
|
+
let(:settings) {BasicDiskSettings.new}
|
5
|
+
|
6
|
+
before do
|
7
|
+
settings.clear
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:a) { SettingName.new :a}
|
11
|
+
let(:b) { SettingName.new :b}
|
12
|
+
|
13
|
+
it "can store single setting" do
|
14
|
+
settings.set :a => "value"
|
15
|
+
|
16
|
+
expect(settings.get(a).to_s).to eql "value"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can store multiple settings at once" do
|
20
|
+
settings.set :a => "value a", :b => "value b"
|
21
|
+
|
22
|
+
expect(settings.get(a).to_s).to eql "value a"
|
23
|
+
expect(settings.get(b).to_s).to eql "value b"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "overwrites duplicates" do
|
27
|
+
settings.set :a => "value a"
|
28
|
+
settings.set :a => "another value for a"
|
29
|
+
|
30
|
+
expect(settings.get(a).to_s).to eql "another value for a"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "overwrites duplicates even when setting the same setting" do
|
34
|
+
settings.set :a => "value a", :a => "another value for a"
|
35
|
+
|
36
|
+
expect(settings.get(a).to_s).to eql "another value for a"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "records all settings when you call set multiple times" do
|
40
|
+
settings.set :a => "value a"
|
41
|
+
settings.set :b => "value b"
|
42
|
+
|
43
|
+
expect(settings.get(a).to_s).to_not be_nil
|
44
|
+
expect(settings.get(b).to_s).to_not be_nil
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "rspec"
|
2
|
-
require "rsettings"
|
1
|
+
require "rspec"
|
2
|
+
require "rsettings"
|
@@ -1,56 +1,56 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "a settings fallback" do
|
4
|
-
before do
|
5
|
-
ENV.clear
|
6
|
-
|
7
|
-
@disk_settings = BasicDiskSettings.new do
|
8
|
-
clear
|
9
|
-
set :jazzs_bike_shorts => "tight"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
let (:settings) do
|
14
|
-
Settings.new do
|
15
|
-
with_settings :chain => [EnvironmentSettings, BasicDiskSettings]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
let (:disk_settings) do
|
20
|
-
@disk_settings
|
21
|
-
end
|
22
|
-
|
23
|
-
it "for example, you can fall back to a setting on disk" do
|
24
|
-
expect(settings.jazzs_bike_shorts).to eql "tight"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "you get the environment setting when it exists" do
|
28
|
-
ENV["jazzs_bike_shorts"] = "this is from the environment variables"
|
29
|
-
|
30
|
-
expect(settings.jazzs_bike_shorts).to eql "this is from the environment variables"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "you can fallback one and not another" do
|
34
|
-
ENV["b"] = "env b"
|
35
|
-
|
36
|
-
disk_settings.clear
|
37
|
-
disk_settings.set :a => "disk a", :b => "disk b"
|
38
|
-
|
39
|
-
expect(settings.a).to eql "disk a"
|
40
|
-
expect(settings.b).to eql "env b"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "you can use ONLY disk if you like" do
|
44
|
-
settings = Settings.new do
|
45
|
-
with_settings BasicDiskSettings
|
46
|
-
end
|
47
|
-
|
48
|
-
ENV["ben_rules"] = "expect this to be ignored"
|
49
|
-
|
50
|
-
disk_settings.clear
|
51
|
-
disk_settings.on(:set){|e,args| puts args.first}
|
52
|
-
disk_settings.set :ben_rules => "yes"
|
53
|
-
|
54
|
-
expect(settings.ben_rules).to eql "yes"
|
55
|
-
end
|
56
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "a settings fallback" do
|
4
|
+
before do
|
5
|
+
ENV.clear
|
6
|
+
|
7
|
+
@disk_settings = BasicDiskSettings.new do
|
8
|
+
clear
|
9
|
+
set :jazzs_bike_shorts => "tight"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let (:settings) do
|
14
|
+
Settings.new do
|
15
|
+
with_settings :chain => [EnvironmentSettings, BasicDiskSettings]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
let (:disk_settings) do
|
20
|
+
@disk_settings
|
21
|
+
end
|
22
|
+
|
23
|
+
it "for example, you can fall back to a setting on disk" do
|
24
|
+
expect(settings.jazzs_bike_shorts).to eql "tight"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "you get the environment setting when it exists" do
|
28
|
+
ENV["jazzs_bike_shorts"] = "this is from the environment variables"
|
29
|
+
|
30
|
+
expect(settings.jazzs_bike_shorts).to eql "this is from the environment variables"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "you can fallback one and not another" do
|
34
|
+
ENV["b"] = "env b"
|
35
|
+
|
36
|
+
disk_settings.clear
|
37
|
+
disk_settings.set :a => "disk a", :b => "disk b"
|
38
|
+
|
39
|
+
expect(settings.a).to eql "disk a"
|
40
|
+
expect(settings.b).to eql "env b"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "you can use ONLY disk if you like" do
|
44
|
+
settings = Settings.new do
|
45
|
+
with_settings BasicDiskSettings
|
46
|
+
end
|
47
|
+
|
48
|
+
ENV["ben_rules"] = "expect this to be ignored"
|
49
|
+
|
50
|
+
disk_settings.clear
|
51
|
+
disk_settings.on(:set){|e,args| puts args.first}
|
52
|
+
disk_settings.set :ben_rules => "yes"
|
53
|
+
|
54
|
+
expect(settings.ben_rules).to eql "yes"
|
55
|
+
end
|
56
|
+
end
|