pakada-dispatch 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  rvm:
2
- - ruby-1.8.7
3
- - ruby-1.9.2
4
- - ruby-head
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
5
  - jruby
6
6
  - rbx-2.0
7
7
  - ree
data/Gemfile CHANGED
@@ -7,5 +7,3 @@ gem "awesome_print"
7
7
 
8
8
  gem "thin"
9
9
  gem "shotgun"
10
-
11
- gem "hatetepe", :path => "../hatetepe"
@@ -1,3 +1,4 @@
1
+ require "hooked"
1
2
  require "http_router"
2
3
  require "pakada"
3
4
 
@@ -12,10 +13,16 @@ class Pakada::Dispatch
12
13
 
13
14
  def initialize
14
15
  @router = HttpRouter.new
16
+ Pakada.safety(Controller).extend Hooked
17
+ Pakada.safety(Controller).around(:included) {|inner, klass|
18
+ klass.send :include, Hooked
19
+ klass.extend Hooked
20
+ inner.call klass
21
+ }
15
22
  end
16
23
 
17
24
  def hooks
18
- Pakada.instance.instead_of :request, @router.method(:call)
25
+ Pakada.instance.instead_of(:request) {|env| request env }
19
26
  end
20
27
 
21
28
  def boot
@@ -25,4 +32,8 @@ class Pakada::Dispatch
25
32
  mod.routes if mod.respond_to? :routes
26
33
  }
27
34
  end
35
+
36
+ def request(env)
37
+ router.call env
38
+ end
28
39
  end
@@ -49,7 +49,7 @@ class Pakada
49
49
  def action(name, options = {}, &block)
50
50
  if block
51
51
  actions[name] = proc {|env, *args|
52
- opts = args[0] || {}
52
+ opts = (args[0] || {}).merge(:action => name)
53
53
  action = self.new(env, options.merge(opts), &block)
54
54
  action.response.finish unless opts[:response]
55
55
  }
@@ -13,7 +13,12 @@ class Pakada
13
13
 
14
14
  def controller(name, &block)
15
15
  if block
16
- controllers[name] = Pakada.safety(Controller).create(&block)
16
+ controllers[name] = Pakada.safety(Controller).create(&block).tap {|c|
17
+ c.before(:new) {|env, *args|
18
+ options = args[0] || {}
19
+ options.merge! :module => pakada_name, :controller => name
20
+ }
21
+ }
17
22
  else
18
23
  controllers[name]
19
24
  end
@@ -1,5 +1,5 @@
1
1
  class Pakada
2
2
  class Dispatch
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -135,7 +135,7 @@ describe Pakada::Dispatch::Controller do
135
135
  it "'s proc creates a controller object passing env, options and block" do
136
136
  ctrlr.should_receive(:new) {|e, opts, &blk|
137
137
  e.should equal(env)
138
- opts.should == merged_options
138
+ opts.values_at(*merged_options.keys).should == merged_options.values
139
139
  blk.should equal(block)
140
140
  }
141
141
  ctrlr.action(:foo).call env, override_options
@@ -145,6 +145,13 @@ describe Pakada::Dispatch::Controller do
145
145
  ctrlr.action(:foo).call(env).should equal(response.finish)
146
146
  end
147
147
 
148
+ it "'s proc adds the action's name to the options hash" do
149
+ ctrlr.should_receive(:new) {|e, opts|
150
+ opts[:action].should equal(:foo)
151
+ }
152
+ ctrlr.action(:foo).call env
153
+ end
154
+
148
155
  it "'s proc returns nothing if a response gets passed in via options" do
149
156
  ctrlr.action(:foo).call(env, :response => response).should be_nil
150
157
  end
@@ -13,12 +13,34 @@ describe Pakada::Dispatch do
13
13
  it "sets the router" do
14
14
  dispatch.router.should equal(router)
15
15
  end
16
+
17
+ let(:controller) { Pakada.safety(Pakada::Dispatch::Controller) }
18
+ let(:klass) { stub "controller klass" }
19
+ let(:inner) { stub "proc", :call => nil }
20
+
21
+ it "makes Controller and controllers hookable" do
22
+ controller.should_receive(:around) {|method, &block|
23
+ method.should equal(:included)
24
+
25
+ klass.should_receive(:extend).with Hooked
26
+ klass.should_receive(:include).with Hooked
27
+ block.call inner, klass
28
+ }
29
+ dispatch
30
+ controller.method :hooked
31
+ end
16
32
  end
17
33
 
18
34
  context "#hooks" do
35
+ let(:env) { stub "env" }
36
+ let(:response) { stub "response" }
37
+
19
38
  it "replaces Pakada#request with router#call" do
20
- Pakada.instance.should_receive(:instead_of).with(
21
- :request, dispatch.router.method(:call))
39
+ Pakada.instance.should_receive(:instead_of) {|name, &block|
40
+ name.should == :request
41
+ dispatch.should_receive(:request).with(env) { response }
42
+ block.call(env).should equal(response)
43
+ }
22
44
  dispatch.hooks
23
45
  end
24
46
  end
@@ -32,7 +32,7 @@ describe Pakada::Dispatch::Module do
32
32
 
33
33
  context "#controller(name) { ... }" do
34
34
  let(:block) { proc {} }
35
- let(:controller) { stub "controller" }
35
+ let(:controller) { stub "controller", :before => nil }
36
36
  let(:dispatch) { Pakada::Dispatch.new }
37
37
 
38
38
  before {
@@ -49,6 +49,20 @@ describe Pakada::Dispatch::Module do
49
49
  mod.controller :bar, &block
50
50
  mod.controllers[:bar].should equal(controller)
51
51
  end
52
+
53
+ let(:options) { {} }
54
+
55
+ it "hooks the controller class' .new method to add module and controller name to options" do
56
+ Pakada.safety(Pakada::Dispatch::Controller) \
57
+ .should_receive(:create) { controller }
58
+ controller.should_receive(:before) {|method, &blk|
59
+ method.should equal(:new)
60
+ blk.call nil, options
61
+ options[:module].should equal(:foo)
62
+ options[:controller].should equal(:bar)
63
+ }
64
+ mod.controller(:bar) {}
65
+ end
52
66
  end
53
67
 
54
68
  context "#load_controllers" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakada-dispatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.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-08-19 00:00:00.000000000Z
12
+ date: 2011-09-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pakada
16
- requirement: &75057660 !ruby/object:Gem::Requirement
16
+ requirement: &85649150 !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: *75057660
24
+ version_requirements: *85649150
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: http_router
27
- requirement: &75057450 !ruby/object:Gem::Requirement
27
+ requirement: &85648750 !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: *75057450
35
+ version_requirements: *85648750
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack
38
- requirement: &75057240 !ruby/object:Gem::Requirement
38
+ requirement: &85648260 !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: :runtime
45
45
  prerelease: false
46
- version_requirements: *75057240
46
+ version_requirements: *85648260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &75057010 !ruby/object:Gem::Requirement
49
+ requirement: &85647280 !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: *75057010
57
+ version_requirements: *85647280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &75056780 !ruby/object:Gem::Requirement
60
+ requirement: &85646720 !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: *75056780
68
+ version_requirements: *85646720
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdiscount
71
- requirement: &75056570 !ruby/object:Gem::Requirement
71
+ requirement: &85646210 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *75056570
79
+ version_requirements: *85646210
80
80
  description:
81
81
  email:
82
82
  - lars.gierth@gmail.com
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 1.8.8
125
+ rubygems_version: 1.8.10
126
126
  signing_key:
127
127
  specification_version: 3
128
128
  summary: Routing And Action Controllers For Pakada