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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzZlMmJhOTY0NDI0NDMzZjliMTU0Y2U3MmRlNTIwMGExMTdiOGQ2MA==
5
+ data.tar.gz: !binary |-
6
+ MDM5NDUxZDE0M2YxNDNkMTE4NDI5OGZiMzQ2N2Q3ZjNmZGRhNjg3Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDc4NjA2ODUxZDFjY2ViM2Q4YmMwNTE3ZDU5MzI3ZjAyYTIzYmJjMWEzZGJi
10
+ NGJiMzk2OTBjNDE5YzlhNGRmN2Y5MjU4MzFjNTc0MmVkYjFiNmE5NTE0NGRl
11
+ YjRmMmZkZDc2NTY1NzBmYjQ3NDZjODQ2NDE4MmI4ODQ1Yzg0N2I=
12
+ data.tar.gz: !binary |-
13
+ ODdkMjgwMjYzMDAyNDBjNTA1NTJiNjBiMmM4MjNmYjk0YjBkMjBjYTE5NGFi
14
+ MGVhNDU1Y2JjYTJiZjVjYTVhMTJjMzQ2MTkwYWIwMjU3N2Q0YTE3M2QyYjM1
15
+ YzdkNzk3YTk5MzJhOGFmMjNiYWM3OGQ3NzY5ZjllY2QwNDBmMjc=
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,65 +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
- oauth2 (0.9.2)
38
- faraday (~> 0.8)
39
- httpauth (~> 0.2)
40
- jwt (~> 0.1.4)
41
- multi_json (~> 1.0)
42
- multi_xml (~> 0.5)
43
- rack (~> 1.2)
44
- rack (1.5.2)
45
- rake (10.1.0)
46
- rdoc (4.0.1)
47
- json (~> 1.4)
48
- rspec (2.14.1)
49
- rspec-core (~> 2.14.0)
50
- rspec-expectations (~> 2.14.0)
51
- rspec-mocks (~> 2.14.0)
52
- rspec-core (2.14.4)
53
- rspec-expectations (2.14.0)
54
- diff-lcs (>= 1.1.3, < 2.0)
55
- rspec-mocks (2.14.1)
56
-
57
- PLATFORMS
58
- ruby
59
-
60
- DEPENDENCIES
61
- audible
62
- bundler
63
- jeweler (~> 1.8.4)
64
- rake
65
- 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.4.0
1
+ 0.5.0
@@ -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
@@ -1,14 +1,14 @@
1
- class EnvironmentSettings
2
- require "audible"; include Audible;
3
-
4
- def get(name)
5
- v = ENV[name.value.to_s]
6
- Setting.new(v).tap{|it| notify_missing(name) if it.missing?}
7
- end
8
-
9
- private
10
-
11
- def notify_missing(name)
12
- notify :missing, name
13
- end
14
- end
1
+ class EnvironmentSettings
2
+ require "audible"; include Audible;
3
+
4
+ def get(name)
5
+ v = ENV[name.value.to_s]
6
+ Setting.new(v).tap{|it| notify_missing(name) if it.missing?}
7
+ end
8
+
9
+ private
10
+
11
+ def notify_missing(name)
12
+ notify :missing, name
13
+ end
14
+ end
@@ -1,20 +1,20 @@
1
- class Defaults
2
- def initialize(names)
3
- @names = names
4
- end
5
-
6
- def get(setting)
7
- real_name = @names.reverse_for setting
8
- Setting.new defaults[real_name]
9
- end
10
-
11
- def add(name, value)
12
- defaults[name] = value
13
- end
14
-
15
- def any?; false == defaults.empty? end
16
-
17
- private
18
-
19
- def defaults; @defaults ||= {}; end
20
- end
1
+ class Defaults
2
+ def initialize(names)
3
+ @names = names
4
+ end
5
+
6
+ def get(setting)
7
+ real_name = @names.reverse_for setting
8
+ Setting.new defaults[real_name]
9
+ end
10
+
11
+ def add(name, value)
12
+ defaults[name] = value
13
+ end
14
+
15
+ def any?; false == defaults.empty? end
16
+
17
+ private
18
+
19
+ def defaults; @defaults ||= {}; end
20
+ end
@@ -1,18 +1,18 @@
1
- class SettingsChain
2
- def initialize(*links)
3
- @settings = *links.flatten
4
- end
5
-
6
- def link(link)
7
- @settings << link
8
- end
9
-
10
- def get(name)
11
- @settings.each do |setting|
12
- result = setting.get(name)
13
- return result unless result.missing?
14
- end
15
-
16
- Setting.new nil
17
- end
18
- end
1
+ class SettingsChain
2
+ def initialize(*links)
3
+ @settings = *links.flatten
4
+ end
5
+
6
+ def link(link)
7
+ @settings << link
8
+ end
9
+
10
+ def get(name)
11
+ @settings.each do |setting|
12
+ result = setting.get(name)
13
+ return result unless result.missing?
14
+ end
15
+
16
+ Setting.new nil
17
+ end
18
+ end
@@ -1,41 +1,41 @@
1
- class SettingsConfiguration
2
- attr_reader :missing, :settings, :names
3
-
4
- def initialize(&block)
5
- @names = Names.new
6
- @defaults = Defaults.new @names
7
- @settings = EnvironmentSettings.new
8
-
9
- instance_exec &block if block_given?
10
-
11
- @settings = SettingsChain.new(@settings).tap do |it|
12
- it.link @defaults if defaults?
13
- it.link tail
14
- end
15
- end
16
-
17
- def let(opts = {})
18
- @names.add opts
19
- end
20
-
21
- def default(name, opts = {})
22
- fail "Expected the :to option so I can tell what the default value is" unless opts[:to]
23
- @defaults.add name, opts[:to]
24
- end
25
-
26
- def when_missing(type)
27
- @tail = IgnoreMissing if type === :ignore
28
- end
29
-
30
- def with_settings(opts={})
31
- @settings = opts.is_a?(Hash) ? SettingsChain.new(opts[:chain].map{|it| it.new}) : opts.new
32
- end
33
-
34
- private
35
-
36
- def tail
37
- @tail || FailOnMissing
38
- end
39
-
40
- def defaults?; @defaults.any? end
41
- end
1
+ class SettingsConfiguration
2
+ attr_reader :missing, :settings, :names
3
+
4
+ def initialize(&block)
5
+ @names = Names.new
6
+ @defaults = Defaults.new @names
7
+ @settings = EnvironmentSettings.new
8
+
9
+ instance_exec &block if block_given?
10
+
11
+ @settings = SettingsChain.new(@settings).tap do |it|
12
+ it.link @defaults if defaults?
13
+ it.link tail
14
+ end
15
+ end
16
+
17
+ def let(opts = {})
18
+ @names.add opts
19
+ end
20
+
21
+ def default(name, opts = {})
22
+ fail "Expected the :to option so I can tell what the default value is" unless opts[:to]
23
+ @defaults.add name, opts[:to]
24
+ end
25
+
26
+ def when_missing(type)
27
+ @tail = IgnoreMissing if type === :ignore
28
+ end
29
+
30
+ def with_settings(opts={})
31
+ @settings = opts.is_a?(Hash) ? SettingsChain.new(opts[:chain].map{|it| it.new}) : opts.new
32
+ end
33
+
34
+ private
35
+
36
+ def tail
37
+ @tail || FailOnMissing
38
+ end
39
+
40
+ def defaults?; @defaults.any? end
41
+ end
@@ -1,15 +1,15 @@
1
- module Missing
2
- def get(name)
3
- Setting.new nil
4
- end
5
- end
6
-
7
- class IgnoreMissing
8
- extend Missing
9
- end
10
-
11
- class FailOnMissing
12
- class << self
13
- def get(name); fail "Setting <#{name.value}> not found"; end
14
- end
15
- end
1
+ module Missing
2
+ def get(name)
3
+ Setting.new nil
4
+ end
5
+ end
6
+
7
+ class IgnoreMissing
8
+ extend Missing
9
+ end
10
+
11
+ class FailOnMissing
12
+ class << self
13
+ def get(name); fail "Setting <#{name.value}> not found"; end
14
+ end
15
+ end