rsettings 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +10 -10
- data/Gemfile +10 -10
- data/Gemfile.lock +67 -67
- data/LICENSE.txt +20 -20
- data/README.md +6 -6
- data/Rakefile +34 -34
- data/VERSION +1 -1
- data/lib/rsettings.rb +50 -46
- 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 +26 -20
- data/lib/rsettings/core/internal/settings_chain.rb +18 -18
- data/lib/rsettings/core/internal/settings_configuration.rb +45 -41
- data/lib/rsettings/core/missing.rb +15 -15
- data/lib/rsettings/core/names.rb +27 -21
- data/lib/rsettings/core/rsettings.rb +29 -29
- data/lib/rsettings/core/setting.rb +16 -16
- data/lib/rsettings/core/setting_name.rb +15 -15
- data/rsettings.gemspec +79 -79
- 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_list_settings_spec.rb +21 -0
- data/spec/system.tests/can_provide_translations_spec.rb +52 -52
- data/spec/system.tests/can_specify_flags_spec.rb +39 -39
- data/spec/system.tests/can_supply_defaults_for_missing_settings_spec.rb +39 -39
- data/spec/system.tests/can_use_env_spec.rb +37 -37
- data/spec/system.tests/options_spec.rb +18 -18
- metadata +23 -9
- checksums.yaml +0 -15
data/.travis.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 1.9.3
|
4
|
-
- 2.0.0
|
5
|
-
branches:
|
6
|
-
only:
|
7
|
-
- master
|
8
|
-
gemfile: Gemfile
|
9
|
-
notifications:
|
10
|
-
recipients:
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
branches:
|
6
|
+
only:
|
7
|
+
- master
|
8
|
+
gemfile: Gemfile
|
9
|
+
notifications:
|
10
|
+
recipients:
|
11
11
|
- ben.biddington@gmail.com
|
data/Gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gem "audible"
|
4
|
-
|
5
|
-
group :development do
|
6
|
-
gem "rake"
|
7
|
-
gem "rspec"
|
8
|
-
gem "bundler"
|
9
|
-
gem "jeweler", "~> 1.8.4"
|
10
|
-
end
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem "audible"
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem "rake"
|
7
|
+
gem "rspec"
|
8
|
+
gem "bundler"
|
9
|
+
gem "jeweler", "~> 1.8.4"
|
10
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,67 +1,67 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
addressable (2.3.5)
|
5
|
-
audible (0.1.0)
|
6
|
-
builder (3.2.2)
|
7
|
-
diff-lcs (1.2.4)
|
8
|
-
faraday (0.8.8)
|
9
|
-
multipart-post (~> 1.2.0)
|
10
|
-
git (1.2.6)
|
11
|
-
github_api (0.10.1)
|
12
|
-
addressable
|
13
|
-
faraday (~> 0.8.1)
|
14
|
-
hashie (>= 1.2)
|
15
|
-
multi_json (~> 1.4)
|
16
|
-
nokogiri (~> 1.5.2)
|
17
|
-
oauth2
|
18
|
-
hashie (2.0.5)
|
19
|
-
highline (1.6.20)
|
20
|
-
httpauth (0.2.0)
|
21
|
-
jeweler (1.8.8)
|
22
|
-
builder
|
23
|
-
bundler (~> 1.0)
|
24
|
-
git (>= 1.2.5)
|
25
|
-
github_api (= 0.10.1)
|
26
|
-
highline (>= 1.6.15)
|
27
|
-
nokogiri (= 1.5.10)
|
28
|
-
rake
|
29
|
-
rdoc
|
30
|
-
json (1.8.1)
|
31
|
-
jwt (0.1.8)
|
32
|
-
multi_json (>= 1.5)
|
33
|
-
multi_json (1.8.2)
|
34
|
-
multi_xml (0.5.5)
|
35
|
-
multipart-post (1.2.0)
|
36
|
-
nokogiri (1.5.10)
|
37
|
-
nokogiri (1.5.10-x86-mingw32)
|
38
|
-
oauth2 (0.9.2)
|
39
|
-
faraday (~> 0.8)
|
40
|
-
httpauth (~> 0.2)
|
41
|
-
jwt (~> 0.1.4)
|
42
|
-
multi_json (~> 1.0)
|
43
|
-
multi_xml (~> 0.5)
|
44
|
-
rack (~> 1.2)
|
45
|
-
rack (1.5.2)
|
46
|
-
rake (10.1.0)
|
47
|
-
rdoc (4.0.1)
|
48
|
-
json (~> 1.4)
|
49
|
-
rspec (2.14.1)
|
50
|
-
rspec-core (~> 2.14.0)
|
51
|
-
rspec-expectations (~> 2.14.0)
|
52
|
-
rspec-mocks (~> 2.14.0)
|
53
|
-
rspec-core (2.14.4)
|
54
|
-
rspec-expectations (2.14.0)
|
55
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
56
|
-
rspec-mocks (2.14.1)
|
57
|
-
|
58
|
-
PLATFORMS
|
59
|
-
ruby
|
60
|
-
x86-mingw32
|
61
|
-
|
62
|
-
DEPENDENCIES
|
63
|
-
audible
|
64
|
-
bundler
|
65
|
-
jeweler (~> 1.8.4)
|
66
|
-
rake
|
67
|
-
rspec
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
audible (0.1.0)
|
6
|
+
builder (3.2.2)
|
7
|
+
diff-lcs (1.2.4)
|
8
|
+
faraday (0.8.8)
|
9
|
+
multipart-post (~> 1.2.0)
|
10
|
+
git (1.2.6)
|
11
|
+
github_api (0.10.1)
|
12
|
+
addressable
|
13
|
+
faraday (~> 0.8.1)
|
14
|
+
hashie (>= 1.2)
|
15
|
+
multi_json (~> 1.4)
|
16
|
+
nokogiri (~> 1.5.2)
|
17
|
+
oauth2
|
18
|
+
hashie (2.0.5)
|
19
|
+
highline (1.6.20)
|
20
|
+
httpauth (0.2.0)
|
21
|
+
jeweler (1.8.8)
|
22
|
+
builder
|
23
|
+
bundler (~> 1.0)
|
24
|
+
git (>= 1.2.5)
|
25
|
+
github_api (= 0.10.1)
|
26
|
+
highline (>= 1.6.15)
|
27
|
+
nokogiri (= 1.5.10)
|
28
|
+
rake
|
29
|
+
rdoc
|
30
|
+
json (1.8.1)
|
31
|
+
jwt (0.1.8)
|
32
|
+
multi_json (>= 1.5)
|
33
|
+
multi_json (1.8.2)
|
34
|
+
multi_xml (0.5.5)
|
35
|
+
multipart-post (1.2.0)
|
36
|
+
nokogiri (1.5.10)
|
37
|
+
nokogiri (1.5.10-x86-mingw32)
|
38
|
+
oauth2 (0.9.2)
|
39
|
+
faraday (~> 0.8)
|
40
|
+
httpauth (~> 0.2)
|
41
|
+
jwt (~> 0.1.4)
|
42
|
+
multi_json (~> 1.0)
|
43
|
+
multi_xml (~> 0.5)
|
44
|
+
rack (~> 1.2)
|
45
|
+
rack (1.5.2)
|
46
|
+
rake (10.1.0)
|
47
|
+
rdoc (4.0.1)
|
48
|
+
json (~> 1.4)
|
49
|
+
rspec (2.14.1)
|
50
|
+
rspec-core (~> 2.14.0)
|
51
|
+
rspec-expectations (~> 2.14.0)
|
52
|
+
rspec-mocks (~> 2.14.0)
|
53
|
+
rspec-core (2.14.4)
|
54
|
+
rspec-expectations (2.14.0)
|
55
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
56
|
+
rspec-mocks (2.14.1)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
x86-mingw32
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
audible
|
64
|
+
bundler
|
65
|
+
jeweler (~> 1.8.4)
|
66
|
+
rake
|
67
|
+
rspec
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2013 Ben Biddington
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2013 Ben Biddington
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
RSettings
|
2
|
-
========
|
3
|
-
|
4
|
-
[![Build Status](https://secure.travis-ci.org/ben-biddington/rsettings.png)](http://travis-ci.org/ben-biddington/rsettings)
|
5
|
-
|
6
|
-
Settings for ruby programs
|
1
|
+
RSettings
|
2
|
+
========
|
3
|
+
|
4
|
+
[![Build Status](https://secure.travis-ci.org/ben-biddington/rsettings.png)](http://travis-ci.org/ben-biddington/rsettings)
|
5
|
+
|
6
|
+
Settings for ruby programs
|
data/Rakefile
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
gem.name = "rsettings"
|
17
|
-
gem.homepage = "http://github.com/ben-biddington/rsettings"
|
18
|
-
gem.license = "MIT"
|
19
|
-
gem.summary = %Q{Settings for ruby programs}
|
20
|
-
gem.description = %Q{Settings}
|
21
|
-
gem.email = "ben.biddington@gmail.com"
|
22
|
-
gem.authors = ["Ben Biddington"]
|
23
|
-
end
|
24
|
-
|
25
|
-
Jeweler::RubygemsDotOrgTasks.new
|
26
|
-
|
27
|
-
require 'rspec/core/rake_task'
|
28
|
-
|
29
|
-
desc "Run all the tests"
|
30
|
-
RSpec::Core::RakeTask.new(:test) do |t|
|
31
|
-
t.pattern = "spec/**/_spec.rb"
|
32
|
-
end
|
33
|
-
|
34
|
-
task :default => :test
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = "rsettings"
|
17
|
+
gem.homepage = "http://github.com/ben-biddington/rsettings"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{Settings for ruby programs}
|
20
|
+
gem.description = %Q{Settings}
|
21
|
+
gem.email = "ben.biddington@gmail.com"
|
22
|
+
gem.authors = ["Ben Biddington"]
|
23
|
+
end
|
24
|
+
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rspec/core/rake_task'
|
28
|
+
|
29
|
+
desc "Run all the tests"
|
30
|
+
RSpec::Core::RakeTask.new(:test) do |t|
|
31
|
+
t.pattern = "spec/**/_spec.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :test
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/rsettings.rb
CHANGED
@@ -1,46 +1,50 @@
|
|
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
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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 inspect
|
11
|
+
@conf.inspect
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(m, *args, &block)
|
15
|
+
fail "Only support queries, cannot do command <#{m}>" unless args.empty?
|
16
|
+
|
17
|
+
rsettings = RSettings.new(
|
18
|
+
:settings => @conf.settings,
|
19
|
+
:names => @conf.names
|
20
|
+
)
|
21
|
+
|
22
|
+
Probe.new rsettings
|
23
|
+
|
24
|
+
rsettings.find m
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Probe
|
29
|
+
def initialize(names)
|
30
|
+
names.on :finding do |e,args|
|
31
|
+
Log.info "[RSettings] Finding setting for <#{args.first}> by name <#{args[1].value}>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class ConsoleLog
|
37
|
+
class << self
|
38
|
+
def info(what)
|
39
|
+
puts "[INFO] #{what}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class DevNullLog
|
45
|
+
class << self
|
46
|
+
def info(what); end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Log = ENV["LOUD"] == "on" ? ConsoleLog : DevNullLog
|
@@ -1,51 +1,51 @@
|
|
1
|
-
class BasicDiskSettings
|
2
|
-
require "fileutils"; include FileUtils
|
3
|
-
require "audible"; include Audible
|
4
|
-
require "yaml"
|
5
|
-
|
6
|
-
def initialize(&block)
|
7
|
-
@file = ".rsettings"
|
8
|
-
_ensure
|
9
|
-
instance_eval &block if block_given?
|
10
|
-
end
|
11
|
-
|
12
|
-
def clear
|
13
|
-
rm file if exists?
|
14
|
-
end
|
15
|
-
|
16
|
-
def set(opts ={})
|
17
|
-
opts = all.merge opts
|
18
|
-
|
19
|
-
File.open file, "w+" do |io|
|
20
|
-
io.puts opts.to_yaml
|
21
|
-
end
|
22
|
-
|
23
|
-
notify :set, @settings
|
24
|
-
end
|
25
|
-
|
26
|
-
def get(name)
|
27
|
-
Setting.new(settings[name.value]).tap{|result| notify_missing name if result.missing?}
|
28
|
-
end
|
29
|
-
|
30
|
-
def file; @file; end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def settings; @settings ||= all; end
|
35
|
-
|
36
|
-
def all
|
37
|
-
return {} unless exists?
|
38
|
-
|
39
|
-
YAML.load(IO.read(file))
|
40
|
-
end
|
41
|
-
|
42
|
-
def notify_missing(name)
|
43
|
-
notify :missing, name
|
44
|
-
end
|
45
|
-
|
46
|
-
def exists?; File.exists? file; end
|
47
|
-
|
48
|
-
def _ensure
|
49
|
-
touch file
|
50
|
-
end
|
51
|
-
end
|
1
|
+
class BasicDiskSettings
|
2
|
+
require "fileutils"; include FileUtils
|
3
|
+
require "audible"; include Audible
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
def initialize(&block)
|
7
|
+
@file = ".rsettings"
|
8
|
+
_ensure
|
9
|
+
instance_eval &block if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def clear
|
13
|
+
rm file if exists?
|
14
|
+
end
|
15
|
+
|
16
|
+
def set(opts ={})
|
17
|
+
opts = all.merge opts
|
18
|
+
|
19
|
+
File.open file, "w+" do |io|
|
20
|
+
io.puts opts.to_yaml
|
21
|
+
end
|
22
|
+
|
23
|
+
notify :set, @settings
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(name)
|
27
|
+
Setting.new(settings[name.value]).tap{|result| notify_missing name if result.missing?}
|
28
|
+
end
|
29
|
+
|
30
|
+
def file; @file; end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def settings; @settings ||= all; end
|
35
|
+
|
36
|
+
def all
|
37
|
+
return {} unless exists?
|
38
|
+
|
39
|
+
YAML.load(IO.read(file))
|
40
|
+
end
|
41
|
+
|
42
|
+
def notify_missing(name)
|
43
|
+
notify :missing, name
|
44
|
+
end
|
45
|
+
|
46
|
+
def exists?; File.exists? file; end
|
47
|
+
|
48
|
+
def _ensure
|
49
|
+
touch file
|
50
|
+
end
|
51
|
+
end
|