pakada 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -118,38 +118,23 @@ class Pakada
118
118
 
119
119
  @safety = {}
120
120
 
121
- modules, resolved = Array(config[:modules]).dup, false
122
- until resolved
123
- j ||= modules.size
124
- i, j = j, 0
125
-
126
- modules.reverse[0...i].map {|mod|
127
- mod.dependencies
128
- }.flatten.each {|dep|
129
- unless modules.include? dep
130
- modules << dep
131
- j += 1
132
- end
133
- }
134
-
135
- resolved = true if j == 0
136
- end
121
+ path = File.expand_path(config[:path])
122
+ @urls, @path = Array(config[:urls]), Pathname.new(path)
123
+
124
+ modules = resolve_modules(Array(config[:modules]))
137
125
  Pakada.instance(self) {
138
- @modules = modules.inject({}) {|hash, mod|
139
- hash[mod.pakada_name] = safety(mod).new; hash
126
+ @modules = modules.inject({}) {|a, e|
127
+ a[e.pakada_name] = safety(e).allocate; a
140
128
  }
129
+ @modules.each_value {|m| m.send :initialize }
141
130
  }
142
131
 
143
- path = File.expand_path(config[:path])
144
- @urls, @path = Array(config[:urls]), Pathname.new(path)
145
132
  @middleware = []
146
133
  end
147
134
 
148
135
  def boot
149
136
  Pakada.instance(self) {
150
- [:hooks, :boot].each {|m|
151
- modules.each_value {|mod| mod.send m }
152
- }
137
+ [:hooks, :boot].each {|m| modules.each_value &m }
153
138
  } unless Pakada.testing?
154
139
  end
155
140
 
@@ -158,7 +143,11 @@ class Pakada
158
143
  end
159
144
 
160
145
  def call(req_env)
161
- Pakada.instance(self) { to_app.call req_env }
146
+ Pakada.instance(self) {
147
+ to_app.call(req_env).tap {|res|
148
+ res[1].delete_if {|k, v| k =~ /^X-Pakada/ }
149
+ }
150
+ }
162
151
  end
163
152
 
164
153
  def to_app
@@ -171,4 +160,25 @@ class Pakada
171
160
  def request(req_env)
172
161
  Rack::Response.new("Hi, I'm Pakada #{VERSION}").finish
173
162
  end
163
+
164
+ private
165
+
166
+ def resolve_modules(modules)
167
+ modules, resolved = modules.dup, false
168
+ until resolved
169
+ j ||= modules.size
170
+ i, j = j, 0
171
+
172
+ modules.reverse[0...i].map(&:dependencies).flatten.each {|dep|
173
+ unless modules.include? dep
174
+ modules << dep
175
+ j += 1
176
+ end
177
+ }
178
+
179
+ resolved = true if j == 0
180
+ end
181
+
182
+ modules
183
+ end
174
184
  end
@@ -1,3 +1,3 @@
1
1
  class Pakada
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -195,13 +195,19 @@ describe Pakada do
195
195
 
196
196
  context "#initialize(name, config)" do
197
197
  let(:module1) do
198
- stub :new => stub, :pakada_name => :module1, :dependencies => [module2]
198
+ stub :allocate => stub("module1", :send => nil),
199
+ :pakada_name => :module1,
200
+ :dependencies => [module2]
199
201
  end
200
202
  let(:module2) do
201
- stub :new => stub, :pakada_name => :module2, :dependencies => [module3]
203
+ stub :allocate => stub("module2", :send => nil),
204
+ :pakada_name => :module2,
205
+ :dependencies => [module3]
202
206
  end
203
207
  let(:module3) do
204
- stub :new => stub, :pakada_name => :module3, :dependencies => []
208
+ stub :allocate => stub("module3", :send => nil),
209
+ :pakada_name => :module3,
210
+ :dependencies => []
205
211
  end
206
212
  let(:instance) { Pakada.new :foo, :modules => [module1] }
207
213
 
@@ -214,14 +220,18 @@ describe Pakada do
214
220
  end
215
221
 
216
222
  it "resolves and initializes the modules" do
217
- instance.modules[:module1].should equal(module1.new)
218
- instance.modules[:module2].should equal(module2.new)
219
- instance.modules[:module3].should equal(module3.new)
223
+ module1.allocate.should_receive(:send).with :initialize
224
+ module2.allocate.should_receive(:send).with :initialize
225
+ module3.allocate.should_receive(:send).with :initialize
226
+
227
+ instance.modules[:module1].should equal(module1.allocate)
228
+ instance.modules[:module2].should equal(module2.allocate)
229
+ instance.modules[:module3].should equal(module3.allocate)
220
230
  end
221
231
 
222
232
  it "initializes modules in the context of this instance" do
223
- context = nil
224
- module1.should_receive(:new) {
233
+ context = 123
234
+ module1.allocate.should_receive(:send) {
225
235
  context = Pakada.instance
226
236
  }
227
237
 
@@ -246,7 +256,7 @@ describe Pakada do
246
256
  before do
247
257
  1.upto(5) {|i|
248
258
  Pakada::Module.descendants << stub({
249
- :new => stub("module#{i}"),
259
+ :allocate => stub("module#{i}", :send => nil),
250
260
  :pakada_name => :"module#{i}",
251
261
  :dependencies => []
252
262
  })
@@ -322,7 +332,7 @@ describe Pakada do
322
332
  context "#call(env)" do
323
333
  let(:instance) { Pakada.new :foo }
324
334
  let(:env) { stub "env" }
325
- let(:response) { stub "response" }
335
+ let(:response) { [200, {"X-Pakada-Foo" => "bar"}, []] }
326
336
 
327
337
  it "forwards to #to_app.call" do
328
338
  instance.stub :to_app => stub("#to_app")
@@ -337,11 +347,19 @@ describe Pakada do
337
347
  it "forwards in the context of this instance" do
338
348
  instance.should_receive(:to_app) {
339
349
  Pakada.instance.should equal(instance)
340
- proc {}
350
+ proc {|env| response }
341
351
  }
342
352
 
343
353
  instance.call(env)
344
354
  end
355
+
356
+ it "drops response headers that start with X-Pakada" do
357
+ instance.stub :to_app => stub("#to_app")
358
+ instance.to_app.stub :call => response
359
+ instance.call(env).tap {|res|
360
+ res[1].key?("X-Pakada-Foo").should equal(false)
361
+ }
362
+ end
345
363
  end
346
364
 
347
365
  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
4
+ version: 0.3.5
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-27 00:00:00.000000000Z
12
+ date: 2011-10-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &72594210 !ruby/object:Gem::Requirement
16
+ requirement: &71392370 !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: *72594210
24
+ version_requirements: *71392370
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hooked
27
- requirement: &72593940 !ruby/object:Gem::Requirement
27
+ requirement: &71392070 !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: *72593940
35
+ version_requirements: *71392070
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &72593660 !ruby/object:Gem::Requirement
38
+ requirement: &71391770 !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: *72593660
46
+ version_requirements: *71391770
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fakefs
49
- requirement: &72593300 !ruby/object:Gem::Requirement
49
+ requirement: &71391490 !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: *72593300
57
+ version_requirements: *71391490
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: fakefs-require
60
- requirement: &72592820 !ruby/object:Gem::Requirement
60
+ requirement: &71391200 !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: *72592820
68
+ version_requirements: *71391200
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
- requirement: &72592580 !ruby/object:Gem::Requirement
71
+ requirement: &71390780 !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: *72592580
79
+ version_requirements: *71390780
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rdiscount
82
- requirement: &72592310 !ruby/object:Gem::Requirement
82
+ requirement: &71390320 !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: *72592310
90
+ version_requirements: *71390320
91
91
  description:
92
92
  email:
93
93
  - lars.gierth@gmail.com