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.
@@ -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
- class Dispatch
12
- include Pakada::Module
13
-
14
- attr_reader :router
15
-
16
- def initialize
17
- @router = Rack::Mount::RouteSet.new
18
- end
19
-
20
- before :boot, :apply_dispatch_patches, :before => :all, do |ctx|
21
- Pakada.modules.each_value do |m|
22
- m.singleton_class.send :include, Pakada::Dispatch::Module
23
- end
24
- end
25
-
26
- before :boot, :load_controllers do |ctx|
27
- Pakada.modules.each_value do |mod|
28
- mod.load_controllers
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
@@ -20,7 +20,7 @@ class Pakada
20
20
  def self.build(&block)
21
21
  Class.new do
22
22
  include Controller
23
- instance_eval &block if block
23
+ class_eval &block if block
24
24
  end
25
25
  end
26
26
 
@@ -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
- instance_eval File.read(file), file, 1
14
+ class_eval File.read(file), file, 1
15
15
  end
16
16
  end if path
17
17
  end
@@ -1,5 +1,5 @@
1
1
  class Pakada
2
2
  class Dispatch
3
- VERSION = "0.0.5"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -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
 
@@ -7,74 +7,72 @@ describe Pakada::Dispatch do
7
7
  subject.module_name.should == :dispatch
8
8
  end
9
9
 
10
- describe ".initialize" do
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 ".before(:boot, :apply_dispatch_patches)" do
18
- before do
19
- Pakada.load_modules
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 "freedom-patches all loaded modules" do
24
- Pakada.hooking.invoke :boot
25
- Pakada.modules.each_value do |m|
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
- end
31
-
32
- describe ".before(:boot, :load_controllers)" do
33
- before do
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 .load_controllers on each module" do
39
- Pakada.modules.each_value do |mod|
40
- mod.should_receive :load_controllers
41
- end
42
- Pakada.hooking.invoke :boot
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 ".before(:boot, :set_dispatch_app)" do
47
- it "overwrites Pakada.app with its own app" do
48
- Pakada.load_modules
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
- req = {"key" => "value"}
53
- resp = [200, {}, []]
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 ".before(:boot, :freeze_router)" do
60
- it "freezes the router" do
61
- Pakada.load_modules
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[:dispatch].router.should_receive :rehash
65
- Pakada.hooking.invoke :boot
56
+ Pakada[:foo].should_receive :load_controllers
57
+ subject.load_module_controllers
66
58
  end
67
59
  end
68
60
 
69
- describe ".hookable(:dispatch)" do
70
- it "passes the request to the router" do
71
- Pakada.load_modules
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 = {"key" => "value"}
75
- resp = [200, {}, []]
76
- Pakada[:dispatch].router.should_receive(:call).with(req) { resp }
77
- Pakada.hooking.invoke(:dispatch, req).should == resp
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
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-02-11 00:00:00 +01:00
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: 530646867
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: 530646867
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.5.2
128
+ rubygems_version: 1.6.2
129
129
  signing_key:
130
130
  specification_version: 3
131
131
  summary: Routing And Action Controllers For Pakada