pakada-dispatch 0.0.5 → 0.1.0
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/lib/pakada/dispatch.rb +35 -32
- data/lib/pakada/dispatch/controller.rb +1 -1
- data/lib/pakada/dispatch/module.rb +1 -1
- data/lib/pakada/dispatch/version.rb +1 -1
- data/pakada-dispatch.gemspec +1 -1
- data/spec/dispatch_spec.rb +43 -45
- metadata +7 -7
data/lib/pakada/dispatch.rb
CHANGED
@@ -7,38 +7,41 @@ require "pakada/dispatch/controller"
|
|
7
7
|
require "pakada/dispatch/module"
|
8
8
|
require "pakada/dispatch/version"
|
9
9
|
|
10
|
-
class Pakada
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
before :boot, :set_dispatch_app do |ctx|
|
33
|
-
Pakada.app = proc {|env| hookable :dispatch, env }
|
34
|
-
end
|
35
|
-
|
36
|
-
after :boot, :freeze_router do |ctx|
|
37
|
-
router.rehash
|
38
|
-
end
|
39
|
-
|
40
|
-
hookable :dispatch do |ctx|
|
41
|
-
ctx.result = router.call ctx.args
|
10
|
+
class Pakada::Dispatch
|
11
|
+
include Pakada::Module
|
12
|
+
|
13
|
+
attr_reader :router
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@router = Rack::Mount::RouteSet.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def boot
|
20
|
+
apply_patches
|
21
|
+
load_module_controllers
|
22
|
+
set_app
|
23
|
+
freeze_router
|
24
|
+
end
|
25
|
+
|
26
|
+
def apply_patches
|
27
|
+
Pakada.modules.each_value do |m|
|
28
|
+
m.singleton_class.send :include, Module
|
42
29
|
end
|
43
30
|
end
|
31
|
+
|
32
|
+
def load_module_controllers
|
33
|
+
Pakada.modules.each_value {|m| m.load_controllers }
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_app
|
37
|
+
Pakada.app = proc {|env| request env }
|
38
|
+
end
|
39
|
+
|
40
|
+
def freeze_router
|
41
|
+
router.rehash
|
42
|
+
end
|
43
|
+
|
44
|
+
def request(env)
|
45
|
+
router.call env
|
46
|
+
end
|
44
47
|
end
|
@@ -11,7 +11,7 @@ class Pakada
|
|
11
11
|
next unless file.match %r{.*/[a-z0-9_]+\.rb$}
|
12
12
|
name = file.split("/").last.split(".").first
|
13
13
|
@controllers[name.to_sym] = Controller.build do
|
14
|
-
|
14
|
+
class_eval File.read(file), file, 1
|
15
15
|
end
|
16
16
|
end if path
|
17
17
|
end
|
data/pakada-dispatch.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{Routing And Action Controllers For Pakada}
|
13
13
|
#s.description = %q{TODO: Write a gem description}
|
14
14
|
|
15
|
-
s.add_dependency "pakada"
|
15
|
+
s.add_dependency "pakada", "~> 0.2"
|
16
16
|
s.add_dependency "rack-mount"
|
17
17
|
s.add_dependency "yajl-ruby"
|
18
18
|
|
data/spec/dispatch_spec.rb
CHANGED
@@ -7,74 +7,72 @@ describe Pakada::Dispatch do
|
|
7
7
|
subject.module_name.should == :dispatch
|
8
8
|
end
|
9
9
|
|
10
|
-
describe "
|
10
|
+
describe "#initialize" do
|
11
11
|
it "initializes the router" do
|
12
12
|
subject.router.should respond_to :add_route
|
13
13
|
subject.router.should respond_to :call
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
describe "
|
18
|
-
before do
|
19
|
-
|
20
|
-
Pakada.load_hooking
|
17
|
+
describe "#boot" do
|
18
|
+
before :each do
|
19
|
+
[:apply_patches, :load_module_controllers].each {|m| subject.stub m }
|
21
20
|
end
|
22
21
|
|
23
|
-
it "
|
24
|
-
|
25
|
-
|
26
|
-
modules = m.singleton_class.included_modules
|
27
|
-
modules.should include(Pakada::Dispatch::Module)
|
28
|
-
end
|
22
|
+
it "calls #apply_patches" do
|
23
|
+
subject.should_receive :apply_patches
|
24
|
+
subject.boot
|
29
25
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
Pakada.load_modules
|
35
|
-
Pakada.load_hooking
|
26
|
+
|
27
|
+
it "calls #load_module_controllers" do
|
28
|
+
subject.should_receive :load_module_controllers
|
29
|
+
subject.boot
|
36
30
|
end
|
37
31
|
|
38
|
-
it "calls
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
it "calls #set_app" do
|
33
|
+
subject.should_receive :set_app
|
34
|
+
subject.boot
|
35
|
+
end
|
36
|
+
|
37
|
+
it "calls #freeze_router" do
|
38
|
+
subject.should_receive :freeze_router
|
39
|
+
subject.boot
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
|
-
describe "
|
47
|
-
it "
|
48
|
-
Pakada.
|
49
|
-
Pakada.load_hooking
|
50
|
-
Pakada.hooking.invoke :boot
|
43
|
+
describe "#apply_patches" do
|
44
|
+
it "patches Pakada::Module" do
|
45
|
+
Pakada.instance.stub(:modules).and_return :foo => stub("foo module")
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
Pakada.hooking.should_receive(:invoke).with(:dispatch, req) { resp }
|
55
|
-
Pakada.app.call(req).should == resp
|
47
|
+
subject.apply_patches
|
48
|
+
Pakada[:foo].should respond_to(:load_controllers)
|
56
49
|
end
|
57
50
|
end
|
58
51
|
|
59
|
-
describe "
|
60
|
-
it "
|
61
|
-
Pakada.
|
62
|
-
Pakada.load_hooking
|
52
|
+
describe "#load_module_controllers" do
|
53
|
+
it "calls #load_controllers on each module" do
|
54
|
+
Pakada.instance.stub(:modules).and_return :foo => stub("foo module")
|
63
55
|
|
64
|
-
Pakada[:
|
65
|
-
|
56
|
+
Pakada[:foo].should_receive :load_controllers
|
57
|
+
subject.load_module_controllers
|
66
58
|
end
|
67
59
|
end
|
68
60
|
|
69
|
-
describe "
|
70
|
-
it "
|
71
|
-
|
72
|
-
Pakada.load_hooking
|
61
|
+
describe "#set_app" do
|
62
|
+
it "makes Pakada.app.call forward to Dispatch.request" do
|
63
|
+
subject.set_app
|
73
64
|
|
74
|
-
req =
|
75
|
-
resp
|
76
|
-
|
77
|
-
Pakada.
|
65
|
+
req, resp = stub("request"), stub("response")
|
66
|
+
subject.should_receive(:request).with(req).and_return resp
|
67
|
+
|
68
|
+
Pakada.app.call(req).should == resp
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#freeze_router" do
|
73
|
+
it "freezes the router" do
|
74
|
+
subject.router.should_receive :rehash
|
75
|
+
subject.freeze_router
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pakada-dispatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Lars Gierth
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-20 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
23
|
+
version: "0.2"
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: *id001
|
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
requirements:
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
hash:
|
112
|
+
hash: -856977645
|
113
113
|
segments:
|
114
114
|
- 0
|
115
115
|
version: "0"
|
@@ -118,14 +118,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
requirements:
|
119
119
|
- - ">="
|
120
120
|
- !ruby/object:Gem::Version
|
121
|
-
hash:
|
121
|
+
hash: -856977645
|
122
122
|
segments:
|
123
123
|
- 0
|
124
124
|
version: "0"
|
125
125
|
requirements: []
|
126
126
|
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.
|
128
|
+
rubygems_version: 1.6.2
|
129
129
|
signing_key:
|
130
130
|
specification_version: 3
|
131
131
|
summary: Routing And Action Controllers For Pakada
|