rsettings 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +2 -0
- data/VERSION +1 -1
- data/lib/rsettings/adapters/environment_settings.rb +5 -3
- data/lib/rsettings/settings_configuration.rb +33 -0
- data/lib/rsettings.rb +6 -15
- data/rsettings.gemspec +10 -4
- data/spec/system.tests/options_spec.rb +18 -0
- metadata +23 -4
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -1,17 +1,19 @@
|
|
1
1
|
class EnvironmentSettings
|
2
|
+
require "audible"; include Audible;
|
3
|
+
|
2
4
|
def initialize
|
3
5
|
@vars = VariableList.new
|
4
6
|
end
|
5
7
|
|
6
8
|
def get(name)
|
7
9
|
real_name = @vars.name name
|
8
|
-
ENV[name.to_s].tap{|it|
|
10
|
+
ENV[name.to_s].tap{|it| notify_missing(name) if it.nil?}
|
9
11
|
end
|
10
12
|
|
11
13
|
private
|
12
14
|
|
13
|
-
def
|
14
|
-
|
15
|
+
def notify_missing(name)
|
16
|
+
notify :missing, name
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class SettingsConfiguration
|
2
|
+
attr_reader :missing
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@missing = FailOnMissing.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def let(opts = {})
|
9
|
+
_opts.merge! opts.invert
|
10
|
+
end
|
11
|
+
|
12
|
+
def when_missing(type)
|
13
|
+
@missing = IgnoreMissing.new if type === :ignore
|
14
|
+
end
|
15
|
+
|
16
|
+
def name_for(setting)
|
17
|
+
_opts[setting] || setting
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def _opts; @opts ||= {}; end
|
23
|
+
end
|
24
|
+
|
25
|
+
class IgnoreMissing
|
26
|
+
def on_missing(name); end
|
27
|
+
end
|
28
|
+
|
29
|
+
class FailOnMissing
|
30
|
+
def on_missing(name)
|
31
|
+
fail "Setting <#{name}> not found"
|
32
|
+
end
|
33
|
+
end
|
data/lib/rsettings.rb
CHANGED
@@ -4,6 +4,7 @@ Dir.glob(File.join(dir, "rsettings", "**", "*.rb")).each {|f| require f}
|
|
4
4
|
|
5
5
|
class Settings
|
6
6
|
def initialize(&block)
|
7
|
+
@settings = EnvironmentSettings.new
|
7
8
|
@config = SettingsConfiguration.new
|
8
9
|
|
9
10
|
if block_given?
|
@@ -11,6 +12,10 @@ class Settings
|
|
11
12
|
conf.instance_exec &block
|
12
13
|
end
|
13
14
|
end
|
15
|
+
|
16
|
+
@settings.on :missing do |e,args|
|
17
|
+
@config.missing.on_missing args.first
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
def method_missing(m, *args, &block)
|
@@ -18,20 +23,6 @@ class Settings
|
|
18
23
|
|
19
24
|
setting_name = @config.name_for m
|
20
25
|
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class SettingsConfiguration
|
26
|
-
def let(opts = {})
|
27
|
-
_opts.merge! opts.invert
|
26
|
+
@settings.get(setting_name)
|
28
27
|
end
|
29
|
-
|
30
|
-
def name_for(setting)
|
31
|
-
_opts[setting] || setting
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def _opts; @opts ||= {}; end
|
37
28
|
end
|
data/rsettings.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rsettings"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Biddington"]
|
12
|
-
s.date = "2013-12-
|
12
|
+
s.date = "2013-12-10"
|
13
13
|
s.description = "Settings"
|
14
14
|
s.email = "ben.biddington@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".document",
|
22
|
+
".travis.yml",
|
22
23
|
"Gemfile",
|
23
24
|
"Gemfile.lock",
|
24
25
|
"LICENSE.txt",
|
@@ -28,10 +29,12 @@ Gem::Specification.new do |s|
|
|
28
29
|
"VERSION",
|
29
30
|
"lib/rsettings.rb",
|
30
31
|
"lib/rsettings/adapters/environment_settings.rb",
|
32
|
+
"lib/rsettings/settings_configuration.rb",
|
31
33
|
"rsettings.gemspec",
|
32
34
|
"settings.gemspec",
|
33
35
|
"spec/spec_helper.rb",
|
34
|
-
"spec/system.tests/can_use_env_spec.rb"
|
36
|
+
"spec/system.tests/can_use_env_spec.rb",
|
37
|
+
"spec/system.tests/options_spec.rb"
|
35
38
|
]
|
36
39
|
s.homepage = "http://github.com/ben-biddington/rsettings"
|
37
40
|
s.licenses = ["MIT"]
|
@@ -43,17 +46,20 @@ Gem::Specification.new do |s|
|
|
43
46
|
s.specification_version = 3
|
44
47
|
|
45
48
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
-
s.add_runtime_dependency(%q<
|
49
|
+
s.add_runtime_dependency(%q<audible>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
47
51
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
48
52
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
49
53
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
54
|
else
|
55
|
+
s.add_dependency(%q<audible>, [">= 0"])
|
51
56
|
s.add_dependency(%q<rake>, [">= 0"])
|
52
57
|
s.add_dependency(%q<rspec>, [">= 0"])
|
53
58
|
s.add_dependency(%q<bundler>, [">= 0"])
|
54
59
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
55
60
|
end
|
56
61
|
else
|
62
|
+
s.add_dependency(%q<audible>, [">= 0"])
|
57
63
|
s.add_dependency(%q<rake>, [">= 0"])
|
58
64
|
s.add_dependency(%q<rspec>, [">= 0"])
|
59
65
|
s.add_dependency(%q<bundler>, [">= 0"])
|
@@ -0,0 +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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsettings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: audible
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rspec
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,6 +101,7 @@ extra_rdoc_files:
|
|
85
101
|
- README.rdoc
|
86
102
|
files:
|
87
103
|
- .document
|
104
|
+
- .travis.yml
|
88
105
|
- Gemfile
|
89
106
|
- Gemfile.lock
|
90
107
|
- LICENSE.txt
|
@@ -94,10 +111,12 @@ files:
|
|
94
111
|
- VERSION
|
95
112
|
- lib/rsettings.rb
|
96
113
|
- lib/rsettings/adapters/environment_settings.rb
|
114
|
+
- lib/rsettings/settings_configuration.rb
|
97
115
|
- rsettings.gemspec
|
98
116
|
- settings.gemspec
|
99
117
|
- spec/spec_helper.rb
|
100
118
|
- spec/system.tests/can_use_env_spec.rb
|
119
|
+
- spec/system.tests/options_spec.rb
|
101
120
|
homepage: http://github.com/ben-biddington/rsettings
|
102
121
|
licenses:
|
103
122
|
- MIT
|
@@ -113,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
132
|
version: '0'
|
114
133
|
segments:
|
115
134
|
- 0
|
116
|
-
hash:
|
135
|
+
hash: 106447213
|
117
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
137
|
none: false
|
119
138
|
requirements:
|