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
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "that you can translate storage names into whatever setting name you want" do
|
4
|
+
it "can supply mappings" do
|
5
|
+
settings = Settings.new do
|
6
|
+
let "U" => :username
|
7
|
+
let "P" => :password
|
8
|
+
end
|
9
|
+
|
10
|
+
ENV["U"] = "graeme.hay"
|
11
|
+
ENV["P"] = "allblacks"
|
12
|
+
|
13
|
+
expect(settings.username).to eql "graeme.hay"
|
14
|
+
expect(settings.password).to eql "allblacks"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "you can map some and not others" do
|
18
|
+
settings_configured_with_username_mapping_only = Settings.new do
|
19
|
+
let "U" => :username
|
20
|
+
end
|
21
|
+
|
22
|
+
ENV["U"] = "graeme.hay"
|
23
|
+
ENV["P"] = "allblacks"
|
24
|
+
|
25
|
+
expect(settings_configured_with_username_mapping_only.username).to eql "graeme.hay"
|
26
|
+
expect(settings_configured_with_username_mapping_only.P).to eql "allblacks"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "you can map none" do
|
30
|
+
settings_configured_with_nothing = Settings.new do
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
ENV["U"] = "graeme.hay"
|
35
|
+
ENV["P"] = "allblacks"
|
36
|
+
|
37
|
+
expect(settings_configured_with_nothing.U).to eql "graeme.hay"
|
38
|
+
expect(settings_configured_with_nothing.P).to eql "allblacks"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "when the setting is not found it tells you the mapped name, not the storage name" do
|
42
|
+
settings = Settings.new do
|
43
|
+
let "U" => :username
|
44
|
+
end
|
45
|
+
|
46
|
+
ENV.clear
|
47
|
+
|
48
|
+
pending "Needs to translate the setting name when telling you it's missing" do
|
49
|
+
expect{settings.username}.to raise_error /Setting <username> not found/
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,31 +1,39 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "settings that are either true or false" do
|
4
|
-
let(:settings){Settings.new}
|
5
|
-
|
6
|
-
before { ENV.clear }
|
7
|
-
|
8
|
-
it "returns a flag when value is 'yes' or 'no'" do
|
9
|
-
ENV["allowed"] = "yes"
|
10
|
-
ENV["disallowed"] = "no"
|
11
|
-
|
12
|
-
expect(settings.allowed?).to be_true
|
13
|
-
expect(settings.disallowed?).to be_false
|
14
|
-
end
|
15
|
-
|
16
|
-
it "
|
17
|
-
ENV["allowed"] = "
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "settings that are either true or false" do
|
4
|
+
let(:settings){Settings.new}
|
5
|
+
|
6
|
+
before { ENV.clear }
|
7
|
+
|
8
|
+
it "returns a flag when value is 'yes' or 'no'" do
|
9
|
+
ENV["allowed"] = "yes"
|
10
|
+
ENV["disallowed"] = "no"
|
11
|
+
|
12
|
+
expect(settings.allowed?).to be_true
|
13
|
+
expect(settings.disallowed?).to be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
it "also supports 'on' and 'off'" do
|
17
|
+
ENV["allowed"] = "on"
|
18
|
+
ENV["disallowed"] = "off"
|
19
|
+
|
20
|
+
expect(settings.allowed?).to be_true
|
21
|
+
expect(settings.disallowed?).to be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "any other value returns setting not found" do
|
25
|
+
ENV["allowed"] = "xxx"
|
26
|
+
|
27
|
+
expect{settings.allowed?}.to raise_error /Unable to convert setting <allowed> to flag/
|
28
|
+
end
|
29
|
+
|
30
|
+
it "accepts mapped setting names, too" do
|
31
|
+
settings = Settings.new do
|
32
|
+
let "V" => "verbose"
|
33
|
+
end
|
34
|
+
|
35
|
+
ENV["V"] = "yes"
|
36
|
+
|
37
|
+
expect(settings.verbose?).to be_true
|
38
|
+
end
|
39
|
+
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "default values for missing settings" do
|
4
|
-
it "can be configured to use a default when setting is missing" do
|
5
|
-
settings = Settings.new do
|
6
|
-
default :colour, :to => "red"
|
7
|
-
end
|
8
|
-
|
9
|
-
expect(settings.colour).to eql "red"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "can be overwritten -- the last set one wins" do
|
13
|
-
settings = Settings.new do
|
14
|
-
default :colour, :to => "red"
|
15
|
-
default :colour, :to => "gold"
|
16
|
-
end
|
17
|
-
|
18
|
-
expect(settings.colour).to eql "gold"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "you can default a mapped setting" do
|
22
|
-
settings = Settings.new do
|
23
|
-
let "C" => :colour
|
24
|
-
default :colour, :to => "green"
|
25
|
-
end
|
26
|
-
|
27
|
-
expect(settings.colour).to eql "green"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "is ignored if present elsewhere" do
|
31
|
-
settings = Settings.new do
|
32
|
-
default :colour, :to => "red"
|
33
|
-
end
|
34
|
-
|
35
|
-
ENV["colour"] = "pink"
|
36
|
-
|
37
|
-
expect(settings.colour).to eql "pink"
|
38
|
-
end
|
39
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "default values for missing settings" do
|
4
|
+
it "can be configured to use a default when setting is missing" do
|
5
|
+
settings = Settings.new do
|
6
|
+
default :colour, :to => "red"
|
7
|
+
end
|
8
|
+
|
9
|
+
expect(settings.colour).to eql "red"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can be overwritten -- the last set one wins" do
|
13
|
+
settings = Settings.new do
|
14
|
+
default :colour, :to => "red"
|
15
|
+
default :colour, :to => "gold"
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(settings.colour).to eql "gold"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "you can default a mapped setting" do
|
22
|
+
settings = Settings.new do
|
23
|
+
let "C" => :colour
|
24
|
+
default :colour, :to => "green"
|
25
|
+
end
|
26
|
+
|
27
|
+
expect(settings.colour).to eql "green"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "is ignored if present elsewhere" do
|
31
|
+
settings = Settings.new do
|
32
|
+
default :colour, :to => "red"
|
33
|
+
end
|
34
|
+
|
35
|
+
ENV["colour"] = "pink"
|
36
|
+
|
37
|
+
expect(settings.colour).to eql "pink"
|
38
|
+
end
|
39
|
+
end
|
@@ -1,74 +1,37 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Can use environment variables as a settings list" do
|
4
|
-
it "an example" do
|
5
|
-
ENV["xxx"] = "bangerman"
|
6
|
-
expect(Settings.new.xxx).to eql "bangerman"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "name may be used (name is interesting because it is implemented on Object)" do
|
10
|
-
ENV["name"] = "bangerman"
|
11
|
-
expect(Settings.new.name).to eql "bangerman"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "fails when setting does not exist" do
|
15
|
-
ENV.clear
|
16
|
-
expect{Settings.new.name}.to raise_error /Setting <name> not found/
|
17
|
-
end
|
18
|
-
|
19
|
-
it "can
|
20
|
-
settings = Settings.new
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
ENV["P"] = "allblacks"
|
39
|
-
|
40
|
-
expect(settings_configured_with_username_mapping_only.username).to eql "graeme.hay"
|
41
|
-
expect(settings_configured_with_username_mapping_only.P).to eql "allblacks"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "you can map none" do
|
45
|
-
settings_configured_with_nothing = Settings.new do
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
ENV["U"] = "graeme.hay"
|
50
|
-
ENV["P"] = "allblacks"
|
51
|
-
|
52
|
-
expect(settings_configured_with_nothing.U).to eql "graeme.hay"
|
53
|
-
expect(settings_configured_with_nothing.P).to eql "allblacks"
|
54
|
-
end
|
55
|
-
|
56
|
-
it "You can have a setting called :new and/or :initialize" do
|
57
|
-
settings = Settings.new
|
58
|
-
|
59
|
-
ENV["new"] = "okay"
|
60
|
-
ENV["initialize"] = "yes please"
|
61
|
-
|
62
|
-
expect(settings.new).to eql "okay"
|
63
|
-
expect(settings.initialize).to eql "yes please"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "make sure you can use setting name 'configure'" do
|
67
|
-
settings = Settings.new
|
68
|
-
|
69
|
-
ENV["configure"] = "xxx_conf_xxx"
|
70
|
-
|
71
|
-
expect(settings.configure).to eql "xxx_conf_xxx"
|
72
|
-
end
|
73
|
-
# Can't use metaclass because class < Object which has lots of methods defined. BasicObject is what we want.
|
74
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Can use environment variables as a settings list" do
|
4
|
+
it "an example" do
|
5
|
+
ENV["xxx"] = "bangerman"
|
6
|
+
expect(Settings.new.xxx).to eql "bangerman"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "name may be used (name is interesting because it is implemented on Object)" do
|
10
|
+
ENV["name"] = "bangerman"
|
11
|
+
expect(Settings.new.name).to eql "bangerman"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "fails when setting does not exist" do
|
15
|
+
ENV.clear
|
16
|
+
expect{Settings.new.name}.to raise_error /Setting <name> not found/
|
17
|
+
end
|
18
|
+
|
19
|
+
it "You can have a setting called :new and/or :initialize" do
|
20
|
+
settings = Settings.new
|
21
|
+
|
22
|
+
ENV["new"] = "okay"
|
23
|
+
ENV["initialize"] = "yes please"
|
24
|
+
|
25
|
+
expect(settings.new).to eql "okay"
|
26
|
+
expect(settings.initialize).to eql "yes please"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "make sure you can use setting name 'configure'" do
|
30
|
+
settings = Settings.new
|
31
|
+
|
32
|
+
ENV["configure"] = "xxx_conf_xxx"
|
33
|
+
|
34
|
+
expect(settings.configure).to eql "xxx_conf_xxx"
|
35
|
+
end
|
36
|
+
# Can't use metaclass because class < Object which has lots of methods defined. BasicObject is what we want.
|
37
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "what to do when a setting is missing" do
|
4
|
-
before { ENV.clear }
|
5
|
-
|
6
|
-
it "fails by default" do
|
7
|
-
settings = Settings.new
|
8
|
-
expect{settings.one_that_does_not_exist}.to raise_error /<one_that_does_not_exist> not found/
|
9
|
-
end
|
10
|
-
|
11
|
-
it "you can instruct it to do nothing" do
|
12
|
-
settings = Settings.new do
|
13
|
-
when_missing :ignore
|
14
|
-
end
|
15
|
-
|
16
|
-
expect(settings.one_that_does_not_exist).to be_nil
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "what to do when a setting is missing" do
|
4
|
+
before { ENV.clear }
|
5
|
+
|
6
|
+
it "fails by default" do
|
7
|
+
settings = Settings.new
|
8
|
+
expect{settings.one_that_does_not_exist}.to raise_error /<one_that_does_not_exist> not found/
|
9
|
+
end
|
10
|
+
|
11
|
+
it "you can instruct it to do nothing" do
|
12
|
+
settings = Settings.new do
|
13
|
+
when_missing :ignore
|
14
|
+
end
|
15
|
+
|
16
|
+
expect(settings.one_that_does_not_exist).to be_nil
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsettings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ben Biddington
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: audible
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: bundler
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,19 +69,19 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: jeweler
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ~>
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
75
|
+
version: !binary |-
|
76
|
+
MS44LjQ=
|
86
77
|
type: :development
|
87
78
|
prerelease: false
|
88
79
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
80
|
requirements:
|
91
81
|
- - ~>
|
92
82
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
83
|
+
version: !binary |-
|
84
|
+
MS44LjQ=
|
94
85
|
description: Settings
|
95
86
|
email: ben.biddington@gmail.com
|
96
87
|
executables: []
|
@@ -121,6 +112,7 @@ files:
|
|
121
112
|
- spec/integration.tests/adapters/basic_disk_settings_spec.rb
|
122
113
|
- spec/spec_helper.rb
|
123
114
|
- spec/system.tests/can_fall_back_to_file_settings_spec.rb
|
115
|
+
- spec/system.tests/can_provide_translations_spec.rb
|
124
116
|
- spec/system.tests/can_specify_flags_spec.rb
|
125
117
|
- spec/system.tests/can_supply_defaults_for_missing_settings_spec.rb
|
126
118
|
- spec/system.tests/can_use_env_spec.rb
|
@@ -128,29 +120,25 @@ files:
|
|
128
120
|
homepage: http://github.com/ben-biddington/rsettings
|
129
121
|
licenses:
|
130
122
|
- MIT
|
123
|
+
metadata: {}
|
131
124
|
post_install_message:
|
132
125
|
rdoc_options: []
|
133
126
|
require_paths:
|
134
127
|
- lib
|
135
128
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
129
|
requirements:
|
138
130
|
- - ! '>='
|
139
131
|
- !ruby/object:Gem::Version
|
140
132
|
version: '0'
|
141
|
-
segments:
|
142
|
-
- 0
|
143
|
-
hash: -70081105
|
144
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
134
|
requirements:
|
147
135
|
- - ! '>='
|
148
136
|
- !ruby/object:Gem::Version
|
149
137
|
version: '0'
|
150
138
|
requirements: []
|
151
139
|
rubyforge_project:
|
152
|
-
rubygems_version: 1.
|
140
|
+
rubygems_version: 2.1.11
|
153
141
|
signing_key:
|
154
|
-
specification_version:
|
142
|
+
specification_version: 4
|
155
143
|
summary: Settings for ruby programs
|
156
144
|
test_files: []
|