rsettings 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
data/lib/rsettings.rb CHANGED
@@ -3,8 +3,35 @@ dir = File.join(File.dirname(__FILE__))
3
3
  Dir.glob(File.join(dir, "rsettings", "**", "*.rb")).each {|f| require f}
4
4
 
5
5
  class Settings
6
- def method_missing(m, *args)
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
+ end
15
+
16
+ def method_missing(m, *args, &block)
7
17
  fail "Only support queries, cannot do <#{m}>" unless args.empty?
8
- EnvironmentSettings.new.get m
18
+
19
+ setting_name = @config.name_for m
20
+
21
+ EnvironmentSettings.new.get(setting_name)
9
22
  end
10
23
  end
24
+
25
+ class SettingsConfiguration
26
+ def let(opts = {})
27
+ _opts.merge! opts.invert
28
+ end
29
+
30
+ def name_for(setting)
31
+ _opts[setting] || setting
32
+ end
33
+
34
+ private
35
+
36
+ def _opts; @opts ||= {}; end
37
+ end
data/rsettings.gemspec ADDED
@@ -0,0 +1,63 @@
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 = "rsettings"
8
+ s.version = "0.1.0"
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/rsettings.rb",
30
+ "lib/rsettings/adapters/environment_settings.rb",
31
+ "rsettings.gemspec",
32
+ "settings.gemspec",
33
+ "spec/spec_helper.rb",
34
+ "spec/system.tests/can_use_env_spec.rb"
35
+ ]
36
+ s.homepage = "http://github.com/ben-biddington/rsettings"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.23"
40
+ s.summary = "Settings for ruby programs"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
47
+ s.add_development_dependency(%q<rspec>, [">= 0"])
48
+ s.add_development_dependency(%q<bundler>, [">= 0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
50
+ else
51
+ s.add_dependency(%q<rake>, [">= 0"])
52
+ s.add_dependency(%q<rspec>, [">= 0"])
53
+ s.add_dependency(%q<bundler>, [">= 0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rake>, [">= 0"])
58
+ s.add_dependency(%q<rspec>, [">= 0"])
59
+ s.add_dependency(%q<bundler>, [">= 0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
61
+ end
62
+ end
63
+
@@ -17,7 +17,63 @@ describe "Can use environment variables as a settings list" do
17
17
  end
18
18
 
19
19
  it "does type matter? Ought I be able to expect numbers for example. Currently all are strings."
20
- it "can supply mappings somehow, so you can have shorter ENV names for example. Translate ENV['n'] => 'name'"
20
+
21
+ it "can supply mappings" do
22
+ settings = Settings.new do
23
+ let "U" => :username
24
+ let "P" => :password
25
+ end
26
+
27
+ ENV["U"] = "graeme.hay"
28
+ ENV["P"] = "allblacks"
29
+
30
+ expect(settings.username).to eql "graeme.hay"
31
+ expect(settings.password).to eql "allblacks"
32
+ end
33
+
34
+ it "you can map some and not others" do
35
+ settings_configured_with_username_mapping_only = Settings.new do
36
+ let "U" => :username
37
+ end
38
+
39
+ ENV["U"] = "graeme.hay"
40
+ ENV["P"] = "allblacks"
41
+
42
+ expect(settings_configured_with_username_mapping_only.username).to eql "graeme.hay"
43
+ expect(settings_configured_with_username_mapping_only.P).to eql "allblacks"
44
+ end
45
+
46
+ it "you can map none" do
47
+ settings_configured_with_nothing = Settings.new do
48
+
49
+ end
50
+
51
+ ENV["U"] = "graeme.hay"
52
+ ENV["P"] = "allblacks"
53
+
54
+ expect(settings_configured_with_nothing.U).to eql "graeme.hay"
55
+ expect(settings_configured_with_nothing.P).to eql "allblacks"
56
+ end
57
+
58
+ it "You can have a setting called :new and/or :initialize" do
59
+ settings = Settings.new
60
+
61
+ ENV["new"] = "okay"
62
+ ENV["initialize"] = "yes please"
63
+
64
+ expect(settings.new).to eql "okay"
65
+ expect(settings.initialize).to eql "yes please"
66
+ end
67
+
68
+ it "make sure you can use setting name 'configure'" do
69
+ settings = Settings.new
70
+
71
+ ENV["configure"] = "xxx_conf_xxx"
72
+
73
+ expect(settings.configure).to eql "xxx_conf_xxx"
74
+ end
75
+
76
+ it "I wonder if ignoring missing settings would be nice -- at least allow me the option"
21
77
 
22
78
  # Can't use metaclass because class < Object which has lots of methods defined. BasicObject is what we want.
23
79
  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.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -94,6 +94,7 @@ files:
94
94
  - VERSION
95
95
  - lib/rsettings.rb
96
96
  - lib/rsettings/adapters/environment_settings.rb
97
+ - rsettings.gemspec
97
98
  - settings.gemspec
98
99
  - spec/spec_helper.rb
99
100
  - spec/system.tests/can_use_env_spec.rb
@@ -112,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
113
  version: '0'
113
114
  segments:
114
115
  - 0
115
- hash: -946123999
116
+ hash: -894220717
116
117
  required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  none: false
118
119
  requirements: