rsettings 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -0,0 +1,13 @@
1
+ class Names
2
+ def initialize
3
+ @opts = {}
4
+ end
5
+
6
+ def add(opts={})
7
+ @opts.merge! opts.invert
8
+ end
9
+
10
+ def for(setting)
11
+ @opts[setting] || setting
12
+ end
13
+ end
@@ -1,9 +1,9 @@
1
1
  class RSettings
2
- def initialize(settings, config)
3
- @settings,@config = settings,config
2
+ def initialize(opts={})
3
+ @settings,@missing,@names = opts[:settings],opts[:missing],opts[:names]
4
4
 
5
5
  @settings.on :missing do |e,args|
6
- @config.missing.on_missing args.first
6
+ @missing.on_missing args.first
7
7
  end
8
8
  end
9
9
 
@@ -12,10 +12,10 @@ class RSettings
12
12
 
13
13
  m = m.to_s.delete "?" if query
14
14
 
15
- setting_name = @config.name_for(m)
15
+ setting_name = @names.for(m)
16
16
 
17
17
  if query
18
- setting_name = @config.name_for(m)
18
+ setting_name = @names.for(m)
19
19
 
20
20
  value = Setting.new @settings.get(setting_name)
21
21
 
@@ -1,23 +1,21 @@
1
1
  class SettingsConfiguration
2
- attr_reader :missing, :settings
2
+ attr_reader :missing, :settings, :names
3
3
 
4
- def initialize
4
+ def initialize(&block)
5
5
  @missing = FailOnMissing.new
6
6
  @settings = EnvironmentSettings.new
7
+ @names = Names.new
8
+ instance_exec &block if block_given?
7
9
  end
8
10
 
9
11
  def let(opts = {})
10
- _opts.merge! opts.invert
12
+ @names.add opts
11
13
  end
12
14
 
13
15
  def when_missing(type)
14
16
  @missing = IgnoreMissing.new if type === :ignore
15
17
  end
16
18
 
17
- def name_for(setting)
18
- _opts[setting] || setting
19
- end
20
-
21
19
  def with_settings(opts={})
22
20
  if opts.is_a? Hash
23
21
  @settings = SettingsChain.new(opts[:chain]) if opts[:chain]
@@ -25,10 +23,6 @@ class SettingsConfiguration
25
23
  @settings = opts.new
26
24
  end
27
25
  end
28
-
29
- private
30
-
31
- def _opts; @opts ||= {}; end
32
26
  end
33
27
 
34
28
  class IgnoreMissing
data/lib/rsettings.rb CHANGED
@@ -4,22 +4,16 @@ Dir.glob(File.join(dir, "rsettings", "**", "*.rb")).each {|f| require f}
4
4
 
5
5
  class Settings
6
6
  def initialize(&block)
7
- @config = SettingsConfiguration.new
8
-
9
- if block_given?
10
- @config = SettingsConfiguration.new.tap do |conf|
11
- conf.instance_exec &block
12
- end
13
- end
14
-
15
- @settings = @config.settings
16
-
17
- fail "Error" unless @config.settings
7
+ @conf = SettingsConfiguration.new &block
18
8
  end
19
9
 
20
10
  def method_missing(m, *args, &block)
21
- fail "Only support queries, cannot do <#{m}>" unless args.empty?
11
+ fail "Only support queries, cannot do command <#{m}>" unless args.empty?
22
12
 
23
- RSettings.new(@settings, @config).find m
13
+ RSettings.new(
14
+ :settings => @conf.settings,
15
+ :missing => @conf.missing,
16
+ :names => @conf.names
17
+ ).find m
24
18
  end
25
19
  end
data/rsettings.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rsettings"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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"]
@@ -14,29 +14,25 @@ Gem::Specification.new do |s|
14
14
  s.email = "ben.biddington@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README.md",
18
- "README.rdoc"
17
+ "README.md"
19
18
  ]
20
19
  s.files = [
21
- ".document",
22
- ".rsettings",
23
20
  ".travis.yml",
24
21
  "Gemfile",
25
22
  "Gemfile.lock",
26
23
  "LICENSE.txt",
27
24
  "README.md",
28
- "README.rdoc",
29
25
  "Rakefile",
30
26
  "VERSION",
31
27
  "lib/rsettings.rb",
32
28
  "lib/rsettings/adapters/basic_disk_settings.rb",
33
29
  "lib/rsettings/adapters/environment_settings.rb",
30
+ "lib/rsettings/internal/names.rb",
34
31
  "lib/rsettings/internal/rsettings.rb",
35
32
  "lib/rsettings/internal/setting.rb",
36
33
  "lib/rsettings/internal/settings_chain.rb",
37
34
  "lib/rsettings/internal/settings_configuration.rb",
38
35
  "rsettings.gemspec",
39
- "settings.gemspec",
40
36
  "spec/integration.tests/adapters/basic_disk_settings_spec.rb",
41
37
  "spec/spec_helper.rb",
42
38
  "spec/system.tests/can_fall_back_to_file_settings_spec.rb",
@@ -15,8 +15,6 @@ describe "Can use environment variables as a settings list" do
15
15
  ENV.clear
16
16
  expect{Settings.new.name}.to raise_error /Setting <name> not found/
17
17
  end
18
-
19
- it "does type matter? Ought I be able to expect numbers for example. Currently all are strings."
20
18
 
21
19
  it "can supply mappings" do
22
20
  settings = Settings.new do
@@ -72,11 +70,5 @@ describe "Can use environment variables as a settings list" do
72
70
 
73
71
  expect(settings.configure).to eql "xxx_conf_xxx"
74
72
  end
75
-
76
- it "I wonder if ignoring missing settings would be nice -- at least allow me the option"
77
-
78
73
  # Can't use metaclass because class < Object which has lots of methods defined. BasicObject is what we want.
79
74
  end
80
-
81
- describe "Can use a file on disk"
82
- describe "Can use a chain of sources, for example ENV falling back to file on disk"
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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -98,27 +98,23 @@ extensions: []
98
98
  extra_rdoc_files:
99
99
  - LICENSE.txt
100
100
  - README.md
101
- - README.rdoc
102
101
  files:
103
- - .document
104
- - .rsettings
105
102
  - .travis.yml
106
103
  - Gemfile
107
104
  - Gemfile.lock
108
105
  - LICENSE.txt
109
106
  - README.md
110
- - README.rdoc
111
107
  - Rakefile
112
108
  - VERSION
113
109
  - lib/rsettings.rb
114
110
  - lib/rsettings/adapters/basic_disk_settings.rb
115
111
  - lib/rsettings/adapters/environment_settings.rb
112
+ - lib/rsettings/internal/names.rb
116
113
  - lib/rsettings/internal/rsettings.rb
117
114
  - lib/rsettings/internal/setting.rb
118
115
  - lib/rsettings/internal/settings_chain.rb
119
116
  - lib/rsettings/internal/settings_configuration.rb
120
117
  - rsettings.gemspec
121
- - settings.gemspec
122
118
  - spec/integration.tests/adapters/basic_disk_settings_spec.rb
123
119
  - spec/spec_helper.rb
124
120
  - spec/system.tests/can_fall_back_to_file_settings_spec.rb
@@ -140,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
136
  version: '0'
141
137
  segments:
142
138
  - 0
143
- hash: -382109293
139
+ hash: -726934447
144
140
  required_rubygems_version: !ruby/object:Gem::Requirement
145
141
  none: false
146
142
  requirements:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rsettings DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- :ben_rules: 'yes'
data/README.rdoc DELETED
@@ -1,19 +0,0 @@
1
- = settings
2
-
3
- Description goes here.
4
-
5
- == Contributing to settings
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2013 Ben Biddington. See LICENSE.txt for
18
- further details.
19
-
data/settings.gemspec DELETED
@@ -1,61 +0,0 @@
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
-
6
- Gem::Specification.new do |s|
7
- s.name = "settings"
8
- s.version = "0.0.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ben Biddington"]
12
- s.date = "2013-12-06"
13
- s.description = "Settings"
14
- s.email = "ben.biddington@gmail.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.md",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".document",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.md",
26
- "README.rdoc",
27
- "Rakefile",
28
- "VERSION",
29
- "lib/settings.rb",
30
- "lib/settings/adapters/environment_settings.rb",
31
- "spec/spec_helper.rb",
32
- "spec/system.tests/can_use_env_spec.rb"
33
- ]
34
- s.homepage = "http://github.com/ben-biddington/settings"
35
- s.licenses = ["MIT"]
36
- s.require_paths = ["lib"]
37
- s.rubygems_version = "1.8.23"
38
- s.summary = "Settings"
39
-
40
- if s.respond_to? :specification_version then
41
- s.specification_version = 3
42
-
43
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_runtime_dependency(%q<rake>, [">= 0"])
45
- s.add_development_dependency(%q<rspec>, [">= 0"])
46
- s.add_development_dependency(%q<bundler>, [">= 0"])
47
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
48
- else
49
- s.add_dependency(%q<rake>, [">= 0"])
50
- s.add_dependency(%q<rspec>, [">= 0"])
51
- s.add_dependency(%q<bundler>, [">= 0"])
52
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
53
- end
54
- else
55
- s.add_dependency(%q<rake>, [">= 0"])
56
- s.add_dependency(%q<rspec>, [">= 0"])
57
- s.add_dependency(%q<bundler>, [">= 0"])
58
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
59
- end
60
- end
61
-