pakada 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -1
- data/lib/pakada/version.rb +1 -1
- data/lib/pakada.rb +29 -27
- data/spec/pakada_spec.rb +42 -5
- metadata +17 -17
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
- LICENSE
|
1
|
+
- LICENSE
|
data/lib/pakada/version.rb
CHANGED
data/lib/pakada.rb
CHANGED
@@ -15,50 +15,48 @@ class Pakada
|
|
15
15
|
attr_reader :instances, :stack
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.instance(
|
19
|
-
return
|
20
|
-
return instances[name] unless block
|
18
|
+
def self.instance(name_or_ins = nil)
|
19
|
+
return stack.last unless name_or_ins
|
21
20
|
|
22
|
-
|
21
|
+
if self === name_or_ins
|
22
|
+
ins = name_or_ins
|
23
|
+
else
|
24
|
+
ins, name = instances[name_or_ins], name_or_ins
|
25
|
+
end
|
26
|
+
return ins unless block_given?
|
27
|
+
|
28
|
+
unless ins
|
23
29
|
dsl = Struct.new(:urls, :modules, :path).new
|
24
|
-
ret =
|
30
|
+
ret = yield(dsl)
|
25
31
|
|
26
|
-
config = Hash[*dsl.members.map
|
32
|
+
config = Hash[*dsl.members.map(&:to_sym).zip(dsl.values).flatten(1)]
|
27
33
|
instances[name] = new(name, config)
|
28
34
|
else
|
29
|
-
|
35
|
+
stack << ins
|
30
36
|
begin
|
31
|
-
ret =
|
37
|
+
ret = yield(ins)
|
32
38
|
ensure
|
33
|
-
|
39
|
+
stack.pop
|
34
40
|
end
|
35
41
|
end
|
36
|
-
|
37
42
|
ret
|
38
43
|
end
|
39
44
|
|
40
45
|
def self.boot
|
41
46
|
instance(:default) {|ins| ins.urls = ["/"] } if instances.empty?
|
42
47
|
|
43
|
-
if instances.keys.length > 1
|
44
|
-
|
48
|
+
@urlmap = if instances.keys.length > 1
|
49
|
+
Rack::URLMap.new instances.values.inject({}) {|map, ins|
|
45
50
|
ins.urls.each {|url|
|
46
|
-
map[url] = proc {|env|
|
47
|
-
instance(ins.name) { ins.call env }
|
48
|
-
}
|
51
|
+
map[url] = proc {|env| ins.call env }
|
49
52
|
}
|
50
53
|
map
|
51
54
|
}
|
52
55
|
else
|
53
|
-
|
54
|
-
@urlmap = proc {|env|
|
55
|
-
instance(ins.name) { ins.call env }
|
56
|
-
}
|
56
|
+
instances.values[0]
|
57
57
|
end
|
58
58
|
|
59
|
-
instances.values.each
|
60
|
-
instance(ins.name) { ins.boot }
|
61
|
-
}
|
59
|
+
instances.values.each &:boot
|
62
60
|
end
|
63
61
|
|
64
62
|
def self.call(env)
|
@@ -136,8 +134,10 @@ class Pakada
|
|
136
134
|
|
137
135
|
resolved = true if j == 0
|
138
136
|
end
|
139
|
-
|
140
|
-
|
137
|
+
Pakada.instance(self) {
|
138
|
+
@modules = modules.inject({}) {|hash, mod|
|
139
|
+
hash[mod.pakada_name] = safety(mod).new; hash
|
140
|
+
}
|
141
141
|
}
|
142
142
|
|
143
143
|
path = File.expand_path(config[:path])
|
@@ -146,8 +146,10 @@ class Pakada
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def boot
|
149
|
-
|
150
|
-
|
149
|
+
Pakada.instance(self) {
|
150
|
+
[:hooks, :boot].each {|m|
|
151
|
+
modules.each_value {|mod| mod.send m }
|
152
|
+
}
|
151
153
|
} unless Pakada.testing?
|
152
154
|
end
|
153
155
|
|
@@ -156,7 +158,7 @@ class Pakada
|
|
156
158
|
end
|
157
159
|
|
158
160
|
def call(req_env)
|
159
|
-
to_app.call req_env
|
161
|
+
Pakada.instance(self) { to_app.call req_env }
|
160
162
|
end
|
161
163
|
|
162
164
|
def to_app
|
data/spec/pakada_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe Pakada do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
context ".instance(name
|
28
|
+
context ".instance(name) {|ins_or_dsl| ... }" do
|
29
29
|
before do
|
30
30
|
Pakada.stub :instances => {
|
31
31
|
:foo => stub("instance: foo"),
|
@@ -66,6 +66,16 @@ describe Pakada do
|
|
66
66
|
|
67
67
|
Pakada.instances[:create_me].should equal(create)
|
68
68
|
end
|
69
|
+
|
70
|
+
let(:baz) { Pakada.allocate }
|
71
|
+
|
72
|
+
it "accepts arbitrary instance objects" do
|
73
|
+
Pakada.instance(baz) {|ins|
|
74
|
+
ins.should equal(baz)
|
75
|
+
Pakada.instance.should equal(baz)
|
76
|
+
Pakada.instances.should_not include(ins)
|
77
|
+
}
|
78
|
+
end
|
69
79
|
end
|
70
80
|
|
71
81
|
context ".boot" do
|
@@ -83,7 +93,6 @@ describe Pakada do
|
|
83
93
|
|
84
94
|
it "creates a Rack::URLMap with end-points for each instance" do
|
85
95
|
foo.should_receive(:call).twice {|e|
|
86
|
-
Pakada.instance.should equal(foo)
|
87
96
|
env.should equal(e)
|
88
97
|
response
|
89
98
|
}
|
@@ -210,6 +219,15 @@ describe Pakada do
|
|
210
219
|
instance.modules[:module3].should equal(module3.new)
|
211
220
|
end
|
212
221
|
|
222
|
+
it "initializes modules in the context of this instance" do
|
223
|
+
context = nil
|
224
|
+
module1.should_receive(:new) {
|
225
|
+
context = Pakada.instance
|
226
|
+
}
|
227
|
+
|
228
|
+
instance.should equal(context)
|
229
|
+
end
|
230
|
+
|
213
231
|
it "sets the URL list" do
|
214
232
|
ins = Pakada.new(:foo, :urls => "http://example.org")
|
215
233
|
ins.urls.should == ["http://example.org"]
|
@@ -266,7 +284,7 @@ describe Pakada do
|
|
266
284
|
Pakada.instance(:instance) {}
|
267
285
|
instance.stub :modules => {
|
268
286
|
:foo => stub("foo module"),
|
269
|
-
:bar => stub("bar module")
|
287
|
+
:bar => stub("bar module", :hooks => nil, :boot => nil)
|
270
288
|
}
|
271
289
|
end
|
272
290
|
|
@@ -288,6 +306,17 @@ describe Pakada do
|
|
288
306
|
|
289
307
|
instance.boot
|
290
308
|
end
|
309
|
+
|
310
|
+
it "calls #hooks and #boot in the context of this instance" do
|
311
|
+
foo.should_receive(:hooks) {
|
312
|
+
Pakada.instance.should equal(instance)
|
313
|
+
}
|
314
|
+
foo.should_receive(:boot) {
|
315
|
+
Pakada.instance.should equal(instance)
|
316
|
+
}
|
317
|
+
|
318
|
+
instance.boot
|
319
|
+
end
|
291
320
|
end
|
292
321
|
|
293
322
|
context "#call(env)" do
|
@@ -295,9 +324,8 @@ describe Pakada do
|
|
295
324
|
let(:env) { stub "env" }
|
296
325
|
let(:response) { stub "response" }
|
297
326
|
|
298
|
-
before { instance.stub :to_app => stub("#to_app") }
|
299
|
-
|
300
327
|
it "forwards to #to_app.call" do
|
328
|
+
instance.stub :to_app => stub("#to_app")
|
301
329
|
instance.to_app.should_receive(:call) {|e|
|
302
330
|
e.should equal(env)
|
303
331
|
response
|
@@ -305,6 +333,15 @@ describe Pakada do
|
|
305
333
|
|
306
334
|
instance.call(env).should equal(response)
|
307
335
|
end
|
336
|
+
|
337
|
+
it "forwards in the context of this instance" do
|
338
|
+
instance.should_receive(:to_app) {
|
339
|
+
Pakada.instance.should equal(instance)
|
340
|
+
proc {}
|
341
|
+
}
|
342
|
+
|
343
|
+
instance.call(env)
|
344
|
+
end
|
308
345
|
end
|
309
346
|
|
310
347
|
context "#to_app" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pakada
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
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-08-
|
12
|
+
date: 2011-08-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &72594210 !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: *72594210
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hooked
|
27
|
-
requirement: &
|
27
|
+
requirement: &72593940 !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: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *72593940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &72593660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *72593660
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: fakefs
|
49
|
-
requirement: &
|
49
|
+
requirement: &72593300 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *72593300
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: fakefs-require
|
60
|
-
requirement: &
|
60
|
+
requirement: &72592820 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *72592820
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
|
-
requirement: &
|
71
|
+
requirement: &72592580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *72592580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rdiscount
|
82
|
-
requirement: &
|
82
|
+
requirement: &72592310 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *72592310
|
91
91
|
description:
|
92
92
|
email:
|
93
93
|
- lars.gierth@gmail.com
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.8.
|
131
|
+
rubygems_version: 1.8.10
|
132
132
|
signing_key:
|
133
133
|
specification_version: 3
|
134
134
|
summary: Modularization contract for web applications
|