configr 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/configr.gemspec +3 -3
- data/lib/configr/configuration_block.rb +3 -0
- data/lib/configr/hash.rb +11 -1
- data/readme.rdoc +12 -4
- data/spec/lib/configuration_block_spec.rb +14 -0
- data/spec/lib/configuration_spec.rb +11 -0
- data/spec/lib/hash_spec.rb +14 -0
- metadata +3 -3
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "configr"
|
8
|
-
gem.summary = "
|
8
|
+
gem.summary = "An elegant approach to creating and accessing configuration values."
|
9
9
|
gem.description = "Configr aims to provide a clean interface to configuring and reading a set of configuration values. The idea evolved from using a standard hash as a configuration store into a more elegant way to declare and read values from within a hash. "
|
10
10
|
gem.email = "josh@josh-nesbitt.net"
|
11
11
|
gem.homepage = "http://github.com/joshnesbitt/configr"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/configr.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{configr}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.9.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Josh Nesbitt"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-01}
|
13
13
|
s.description = %q{Configr aims to provide a clean interface to configuring and reading a set of configuration values. The idea evolved from using a standard hash as a configuration store into a more elegant way to declare and read values from within a hash. }
|
14
14
|
s.email = %q{josh@josh-nesbitt.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.rdoc_options = ["--charset=UTF-8"]
|
41
41
|
s.require_paths = ["lib"]
|
42
42
|
s.rubygems_version = %q{1.3.5}
|
43
|
-
s.summary = %q{
|
43
|
+
s.summary = %q{An elegant approach to creating and accessing configuration values.}
|
44
44
|
s.test_files = [
|
45
45
|
"spec/lib/configuration_block_spec.rb",
|
46
46
|
"spec/lib/configuration_spec.rb",
|
@@ -13,6 +13,9 @@ module Configr
|
|
13
13
|
when name.include?('=')
|
14
14
|
key = name.gsub('=','').to_sym
|
15
15
|
self.attributes[key] = args.first
|
16
|
+
when name.include?("?")
|
17
|
+
key = name.gsub('?','').to_sym
|
18
|
+
!self.attributes[key].nil?
|
16
19
|
when existing_block_attributes = self.attributes[method]
|
17
20
|
existing_block = ConfigurationBlock.new(existing_block_attributes)
|
18
21
|
self.attributes[method] = existing_block.attributes
|
data/lib/configr/hash.rb
CHANGED
@@ -39,7 +39,17 @@ module Configr
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def method_missing(method, *args, &block)
|
42
|
-
|
42
|
+
name = method.to_s
|
43
|
+
|
44
|
+
case
|
45
|
+
when name.include?("=")
|
46
|
+
raise ConfigurationLocked, "Configuration is locked from configuring values after the configuration has been run."
|
47
|
+
when name.include?('?')
|
48
|
+
key = name.gsub('?','').to_sym
|
49
|
+
!self[key].nil?
|
50
|
+
else
|
51
|
+
self[method]
|
52
|
+
end
|
43
53
|
end
|
44
54
|
end
|
45
55
|
end
|
data/readme.rdoc
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
== Overview
|
13
13
|
|
14
|
-
Configr aims to provide a
|
14
|
+
Configr aims to provide a clean interface for configuring and reading a set of configuration values. The idea evolved from using a standard hash as a configuration store into a more elegant way to declare and read values from within a hash.
|
15
15
|
|
16
16
|
|
17
17
|
|
@@ -99,16 +99,24 @@ Conceptually you could continue to nest configuration blocks as far as you wish.
|
|
99
99
|
puts configuration.example_three
|
100
100
|
puts configuration.example_four
|
101
101
|
|
102
|
+
=== Asserting key presence
|
103
|
+
|
104
|
+
Sometimes when using configuration values you might want to assert whether the value exists before using it. Configr allows you to do this the #key_name? methods:
|
105
|
+
|
106
|
+
puts configuration.example_one? # => true
|
107
|
+
puts configuration.doesnt_exist? # => false
|
108
|
+
|
102
109
|
|
103
110
|
|
104
111
|
== Usage (within frameworks)
|
105
112
|
|
106
|
-
Configr is intended to be framework agnostic, but it's easy to get it going inside of Rails/Sinatra
|
113
|
+
Configr is intended to be framework agnostic, but it's easy to get it going inside of Rails/Sinatra.
|
114
|
+
|
107
115
|
|
108
116
|
|
109
117
|
=== Rails
|
110
118
|
|
111
|
-
You can use Configr within Rails quite easily. I don't plan to provide any "out of the box" way to hook Configr into Rails but it's
|
119
|
+
You can use Configr within Rails quite easily. I don't plan to provide any "out of the box" way to hook Configr into Rails but it's easy to implement:
|
112
120
|
|
113
121
|
# In config/configuration.rb
|
114
122
|
yaml_file = Rails.root.join("config", "environments", "#{Rails.env}.yml")
|
@@ -142,7 +150,7 @@ Again, by requiring a different YAML file based on the environment it is easy to
|
|
142
150
|
|
143
151
|
== A note about locking
|
144
152
|
|
145
|
-
By design a configuration value is not meant to be edited or created after the configuration block has been run (if you do you will run into a Configr::ConfigurationLocked error
|
153
|
+
By design a configuration value is not meant to be edited or created after the configuration block has been run (if you do you will run into a Configr::ConfigurationLocked error). In my opinion configurations such as those created by Configr are meant to be read-only during the lifetime of the application. Configr could however be altered to allow this with a simple patch should it be required.
|
146
154
|
|
147
155
|
|
148
156
|
|
@@ -50,5 +50,19 @@ module Configr
|
|
50
50
|
@block.five.six.seven.class.should == ConfigurationBlock
|
51
51
|
end
|
52
52
|
|
53
|
+
it "should return true when using the #method? for asserting a values presence" do
|
54
|
+
@block.variable = "value"
|
55
|
+
@block.another.variable.set = "something"
|
56
|
+
|
57
|
+
@block.variable?.should == true
|
58
|
+
@block.another.variable.set?.should == true
|
59
|
+
|
60
|
+
@block.exists?.should == false
|
61
|
+
@block.exists = "value"
|
62
|
+
@block.exists?.should == true
|
63
|
+
|
64
|
+
@block.another.variable.missing?.should == false
|
65
|
+
end
|
66
|
+
|
53
67
|
end
|
54
68
|
end
|
@@ -30,6 +30,17 @@ module Configr
|
|
30
30
|
configuration.other_value?.should == false
|
31
31
|
end
|
32
32
|
|
33
|
+
it "should return true on a value being present when using the #method? within a nested block" do
|
34
|
+
configuration = Configuration.configure do |config|
|
35
|
+
config.one.two.three = "value"
|
36
|
+
end
|
37
|
+
|
38
|
+
configuration.one?.should == true
|
39
|
+
configuration.one.two?.should == true
|
40
|
+
configuration.one.two.three?.should == true
|
41
|
+
configuration.one.two.five?.should == false
|
42
|
+
end
|
43
|
+
|
33
44
|
it "should raise an error when an existing value attempts to be updated once configuration has been run" do
|
34
45
|
configuration = Configuration.configure do |config|
|
35
46
|
config.key = "value"
|
data/spec/lib/hash_spec.rb
CHANGED
@@ -77,5 +77,19 @@ module Configr
|
|
77
77
|
hash.two.should == "two"
|
78
78
|
end
|
79
79
|
|
80
|
+
it "should return true when using the #method? for asserting a values presence" do
|
81
|
+
hash = Hash.new({ :one => "one", :two => "two" })
|
82
|
+
|
83
|
+
hash.one?.should == true
|
84
|
+
hash.two?.should == true
|
85
|
+
hash.three?.should == false
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should raise an error when a value is assigned" do
|
89
|
+
hash = Hash.new({ :one => "one", :two => "two" })
|
90
|
+
|
91
|
+
lambda { hash.some_value = "this" }.should raise_error(Configr::ConfigurationLocked)
|
92
|
+
end
|
93
|
+
|
80
94
|
end
|
81
95
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Nesbitt
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-01 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -77,7 +77,7 @@ rubyforge_project:
|
|
77
77
|
rubygems_version: 1.3.5
|
78
78
|
signing_key:
|
79
79
|
specification_version: 3
|
80
|
-
summary:
|
80
|
+
summary: An elegant approach to creating and accessing configuration values.
|
81
81
|
test_files:
|
82
82
|
- spec/lib/configuration_block_spec.rb
|
83
83
|
- spec/lib/configuration_spec.rb
|