simpleconf 0.0.2 → 0.0.3
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/README.md +19 -0
- data/lib/simpleconf.rb +12 -2
- data/lib/simpleconf/version.rb +1 -1
- data/spec/files/conf +6 -0
- data/spec/simpleconf_spec.rb +94 -10
- metadata +10 -8
data/README.md
CHANGED
@@ -80,5 +80,24 @@ Needed a simple configuration library for my gems. Made public so everyone can t
|
|
80
80
|
|
81
81
|
default.port 80 #throws error!!!
|
82
82
|
|
83
|
+
**File Configuration**
|
84
|
+
|
85
|
+
# basic.conf
|
86
|
+
|
87
|
+
server "localhost"
|
88
|
+
ports [80, 8080, 3000]
|
89
|
+
auth {
|
90
|
+
user "mike"
|
91
|
+
pass "password"
|
92
|
+
}
|
93
|
+
|
94
|
+
# code.rb
|
95
|
+
|
96
|
+
conf = SimpleConf.load("basic.conf")
|
97
|
+
conf.server # localhost
|
98
|
+
conf.ports # [80, 8080, 3000]
|
99
|
+
conf.auth.user # mike
|
100
|
+
# etc
|
101
|
+
|
83
102
|
|
84
103
|
To see all examples/cases, see the spec file.
|
data/lib/simpleconf.rb
CHANGED
@@ -13,7 +13,17 @@ module SimpleConf
|
|
13
13
|
c
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
def build_from_string(instance_str, opts={})
|
17
|
+
c = Conf.new(instance_str, opts)
|
18
|
+
c.instance_eval(instance_str)
|
19
|
+
c.__init_only__ = true if opts[:init_only]
|
20
|
+
c
|
21
|
+
end
|
17
22
|
|
18
|
-
|
23
|
+
def load(file_name, opts={})
|
24
|
+
build_from_string(File.read(file_name), opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
module_function :build, :build_from_string, :load
|
19
28
|
|
29
|
+
end
|
data/lib/simpleconf/version.rb
CHANGED
data/spec/files/conf
ADDED
data/spec/simpleconf_spec.rb
CHANGED
@@ -28,6 +28,75 @@ describe SimpleConf do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
context "#build_from_string" do
|
32
|
+
before do
|
33
|
+
@str = <<-EOS
|
34
|
+
server "localhost", :override => false
|
35
|
+
port 80
|
36
|
+
auth {
|
37
|
+
user "mike"
|
38
|
+
password "mypass"
|
39
|
+
}
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should create a SimpleConf::Conf from a valid string conf" do
|
44
|
+
c = SimpleConf.build_from_string(@str)
|
45
|
+
|
46
|
+
c.should be_an_instance_of(SimpleConf::Conf)
|
47
|
+
c.server.should == "localhost"
|
48
|
+
c.port.should == 80
|
49
|
+
c.auth.should be_an_instance_of(SimpleConf::Conf)
|
50
|
+
c.auth.user.should == "mike"
|
51
|
+
c.auth.password.should == "mypass"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should create a SimpleConf::Conf that uses ovveride" do
|
55
|
+
c = SimpleConf.build_from_string(@str)
|
56
|
+
|
57
|
+
c.server "boo"
|
58
|
+
c.server.should == "localhost"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should create a SimpleConf::Conf that uses init_only" do
|
62
|
+
c = SimpleConf.build_from_string(@str, :init_only => true)
|
63
|
+
|
64
|
+
lambda { c.boooo("yeaa") }.should raise_error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "#load" do
|
69
|
+
before do
|
70
|
+
@file_name = "./spec/files/conf"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should create a SimpleConf::Conf from a valid string conf" do
|
74
|
+
c = SimpleConf.load(@file_name)
|
75
|
+
|
76
|
+
c.should be_an_instance_of(SimpleConf::Conf)
|
77
|
+
c.server.should == "localhost"
|
78
|
+
c.port.should == 80
|
79
|
+
c.auth.should be_an_instance_of(SimpleConf::Conf)
|
80
|
+
c.auth.user.should == "mike"
|
81
|
+
c.auth.password.should == "mypass"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should create a SimpleConf::Conf that uses ovveride" do
|
85
|
+
c = SimpleConf.load(@file_name)
|
86
|
+
|
87
|
+
c.server "boo"
|
88
|
+
c.server.should == "localhost"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should create a SimpleConf::Conf that uses init_only" do
|
92
|
+
c = SimpleConf.load(@file_name, :init_only => true)
|
93
|
+
|
94
|
+
lambda { c.boooo("yeaa") }.should raise_error
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
end
|
99
|
+
|
31
100
|
it "should create a Kernel method SimpleConf" do
|
32
101
|
Kernel.should respond_to(:SimpleConf)
|
33
102
|
end
|
@@ -77,16 +146,16 @@ describe SimpleConf do
|
|
77
146
|
|
78
147
|
context "Blank Slate" do
|
79
148
|
it "should remove all methods and allow user to do whatever he wants " do
|
80
|
-
|
81
|
-
c = SimpleConf {
|
82
|
-
id 5
|
83
|
-
hash 20
|
84
|
-
freeze "boo"
|
85
|
-
}
|
86
149
|
|
87
|
-
|
88
|
-
|
89
|
-
|
150
|
+
c = SimpleConf {
|
151
|
+
id 5
|
152
|
+
hash 20
|
153
|
+
freeze "boo"
|
154
|
+
}
|
155
|
+
|
156
|
+
c.id.should == 5
|
157
|
+
c.hash.should == 20
|
158
|
+
c.freeze.should == "boo"
|
90
159
|
end
|
91
160
|
|
92
161
|
end
|
@@ -107,7 +176,7 @@ describe SimpleConf do
|
|
107
176
|
}
|
108
177
|
|
109
178
|
lambda {
|
110
|
-
|
179
|
+
c.port "boooo"
|
111
180
|
}.should raise_error
|
112
181
|
end
|
113
182
|
|
@@ -175,6 +244,21 @@ describe SimpleConf do
|
|
175
244
|
c.a.b.c.d.should == 5
|
176
245
|
end
|
177
246
|
|
247
|
+
it "should be able to access the nested namespace" do
|
248
|
+
c = SimpleConf {
|
249
|
+
server {
|
250
|
+
host "localhost"
|
251
|
+
port 80
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
lambda { c.server }.should_not raise_error
|
256
|
+
c.server.should be_an_instance_of(SimpleConf::Conf)
|
257
|
+
p c.server
|
258
|
+
c.server.host.should == "localhost"
|
259
|
+
c.server.port.should == 80
|
260
|
+
end
|
261
|
+
|
178
262
|
it "should allow for editable config elems within nests" do
|
179
263
|
c = SimpleConf {
|
180
264
|
a {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simpleconf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: blankslate
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152682220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152682220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152681800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152681800
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152681380 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152681380
|
47
47
|
description: Simple Configuration DSL that supports merging, locking and more.
|
48
48
|
email:
|
49
49
|
- ft.mikelewis@gmail.com
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/simpleconf/conf.rb
|
63
63
|
- lib/simpleconf/version.rb
|
64
64
|
- simpleconf.gemspec
|
65
|
+
- spec/files/conf
|
65
66
|
- spec/simpleconf_spec.rb
|
66
67
|
- spec/spec_helper.rb
|
67
68
|
homepage: http://github.com/mikelewis/simpleconf
|
@@ -89,5 +90,6 @@ signing_key:
|
|
89
90
|
specification_version: 3
|
90
91
|
summary: Simple Configuration DSL that supports merging, locking and more.
|
91
92
|
test_files:
|
93
|
+
- spec/files/conf
|
92
94
|
- spec/simpleconf_spec.rb
|
93
95
|
- spec/spec_helper.rb
|