labor 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/labor/config.rb +5 -2
- data/lib/labor/version.rb +1 -1
- data/spec/config_spec.rb +45 -39
- metadata +57 -40
data/lib/labor/config.rb
CHANGED
@@ -19,8 +19,9 @@ module Labor
|
|
19
19
|
class Config
|
20
20
|
include Enumerable
|
21
21
|
|
22
|
-
def initialize
|
22
|
+
def initialize(parent = nil)
|
23
23
|
@config = {}
|
24
|
+
@parent = parent unless parent.nil?
|
24
25
|
end
|
25
26
|
|
26
27
|
# Loads a config file.
|
@@ -88,7 +89,7 @@ module Labor
|
|
88
89
|
#
|
89
90
|
# Returns a Boolean of whether or not the key exists.
|
90
91
|
def group(key, &block)
|
91
|
-
@config[key.to_sym]
|
92
|
+
@config[key.to_sym] = Config.new(self)
|
92
93
|
@config[key.to_sym].instance_eval(&block) if block_given?
|
93
94
|
end
|
94
95
|
|
@@ -97,6 +98,8 @@ module Labor
|
|
97
98
|
def method_missing(sym, *args)
|
98
99
|
if args.length == 0 && @config.has_key?(sym)
|
99
100
|
get(sym)
|
101
|
+
else
|
102
|
+
@parent.get(sym) unless @parent.nil?
|
100
103
|
end
|
101
104
|
end
|
102
105
|
end
|
data/lib/labor/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -5,59 +5,65 @@ describe Labor::Config do
|
|
5
5
|
@config = Labor::Config.new
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
describe "config files" do
|
9
|
+
it "can be loaded" do
|
10
|
+
@config.load File.join(File.dirname(__FILE__), 'files', 'sample_config.rb')
|
11
|
+
@config.get(:foo).should == "bar"
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
it "should provide in-line variables for set keys" do
|
15
|
+
@config.instance_eval <<-CONFIG
|
16
|
+
set :foo, "bar"
|
17
|
+
set :i_am, "at the \#{foo}"
|
18
|
+
CONFIG
|
19
|
+
@config.get(:i_am).should == "at the bar"
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
describe "write access" do
|
24
|
+
it "provides access to a key" do
|
25
|
+
@config.set(:foo, "bar")
|
26
|
+
@config.get(:foo).should == "bar"
|
27
|
+
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
it "provides access to keys via bracket method" do
|
30
|
+
@config[:foo] = "bar"
|
31
|
+
@config.get(:foo).should == "bar"
|
32
|
+
end
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
|
34
|
+
it "allows deletion of a key" do
|
35
|
+
@config.set(:foo, "a noob")
|
36
|
+
@config.delete(:foo)
|
37
|
+
@config.get(:foo).should be_nil
|
38
|
+
end
|
31
39
|
end
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
describe "read access" do
|
42
|
+
it "provides access to a key" do
|
43
|
+
@config.set(:foo, "bar")
|
44
|
+
@config.get(:foo).should == "bar"
|
45
|
+
end
|
37
46
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
it "provides access to keys via bracket method" do
|
48
|
+
@config.set(:foo, "bar")
|
49
|
+
@config[:foo].should == "bar"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "provides access to keys using methods" do
|
53
|
+
@config.set(:foo, "bar")
|
54
|
+
@config.foo.should == "bar"
|
55
|
+
end
|
43
56
|
|
44
|
-
|
45
|
-
|
46
|
-
|
57
|
+
it "allows checking existence of a key" do
|
58
|
+
@config.set(:foo, "bar")
|
59
|
+
@config.exists?(:foo)
|
60
|
+
end
|
47
61
|
end
|
48
62
|
|
49
63
|
it "have each defined" do
|
50
64
|
@config.respond_to?(:each)
|
51
65
|
end
|
52
|
-
|
53
|
-
it "allow configs to use keys as in-line variables" do
|
54
|
-
@config.instance_eval <<-CONFIG
|
55
|
-
set :foo, "bar"
|
56
|
-
set :i_am, "at the \#{foo}"
|
57
|
-
CONFIG
|
58
|
-
@config.get(:i_am).should == "at the bar"
|
59
|
-
end
|
60
|
-
|
66
|
+
|
61
67
|
describe :grouping do
|
62
68
|
before(:each) do
|
63
69
|
@config.instance_eval <<-CONFIG
|
metadata
CHANGED
@@ -1,48 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: labor
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Brett Buddin
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
16
|
+
|
17
|
+
date: 2011-03-29 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
16
21
|
name: gearman-ruby
|
17
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
24
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
23
31
|
type: :runtime
|
24
|
-
|
25
|
-
|
26
|
-
- !ruby/object:Gem::Dependency
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
27
34
|
name: json
|
28
|
-
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
37
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
34
44
|
type: :runtime
|
35
|
-
|
36
|
-
|
37
|
-
description: Wrapper for gearman-ruby that provides a different, and more portable,
|
38
|
-
way of defining jobs.
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Wrapper for gearman-ruby that provides a different, and more portable, way of defining jobs.
|
39
47
|
email: brett@intraspirit.net
|
40
48
|
executables: []
|
49
|
+
|
41
50
|
extensions: []
|
42
|
-
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
43
53
|
- LICENSE
|
44
54
|
- README.md
|
45
|
-
files:
|
55
|
+
files:
|
46
56
|
- LICENSE
|
47
57
|
- README.md
|
48
58
|
- Rakefile
|
@@ -61,29 +71,36 @@ files:
|
|
61
71
|
has_rdoc: true
|
62
72
|
homepage: http://github.com/brettbuddin/labor
|
63
73
|
licenses: []
|
74
|
+
|
64
75
|
post_install_message:
|
65
76
|
rdoc_options: []
|
66
|
-
|
77
|
+
|
78
|
+
require_paths:
|
67
79
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
81
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
89
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
80
96
|
requirements: []
|
97
|
+
|
81
98
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
99
|
+
rubygems_version: 1.3.7
|
83
100
|
signing_key:
|
84
101
|
specification_version: 3
|
85
102
|
summary: More portable jobs for Gearman workers.
|
86
|
-
test_files:
|
103
|
+
test_files:
|
87
104
|
- spec/config_spec.rb
|
88
105
|
- spec/files/sample_config.rb
|
89
106
|
- spec/labor_spec.rb
|