public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Merge branch 'master' of git@github.com:wycats/merb-core
wycats (author)
Tue Mar 04 15:53:56 -0800 2008
commit  826d11734cd188ed0c4ff32507a5c4a79a259689
tree    bd484a14f9cb51c1c5272c3e1d4729954ec9dfbe
parent  315e3c81828d33694d3ef279060dbac09a56aadc parent  0b4fb97bf89c9241b2d6a7f26decee2e7a7fc081
...
196
197
198
199
 
200
201
202
...
218
219
220
221
 
222
223
224
...
364
365
366
 
 
367
368
369
...
196
197
198
 
199
200
201
202
...
218
219
220
 
221
222
223
224
...
364
365
366
367
368
369
370
371
0
@@ -196,7 +196,7 @@
0
   # ==== Raises
0
   # MerbControllerError:: Invalid body content caught.
0
   def _dispatch(action=:to_s)
0
- hook :before_dispatch
0
+ setup_session
0
     self.action_name = action
0
     
0
     caught = catch(:halt) do
0
@@ -218,7 +218,7 @@
0
     start = Time.now
0
     _call_filters(_after_filters)
0
     @_benchmarks[:after_filters_time] = Time.now - start if _after_filters
0
- hook :after_dispatch
0
+ finalize_session
0
   end
0
   
0
   # This method exists to provide an overridable hook for ActionArgs
0
@@ -364,6 +364,8 @@
0
   # Defaults that can be overridden by plugins, other mixins, or subclasses
0
   def _filters_halted() "<html><body><h1>Filter Chain Halted!</h1></body></html>" end
0
 
0
+ def setup_session() end
0
+ def finalize_session() end
0
   # Stub so content-type support in RenderMixin doesn't throw errors
0
   attr_accessor :content_type
0
   
...
10
11
12
13
14
15
16
17
18
 
 
 
 
 
19
20
21
22
 
 
 
23
24
25
26
 
 
27
28
29
...
10
11
12
 
 
 
 
 
 
13
14
15
16
17
18
 
 
 
19
20
21
22
 
 
 
23
24
25
26
27
0
@@ -10,20 +10,18 @@
0
     #
0
     # ==== Parameters
0
     # base<Class>:: The class to which the SessionMixin is mixed into.
0
- def self.included(base)
0
- base.add_hook :before_dispatch do
0
- Merb.logger.info("Setting Up Cookie Store Sessions")
0
- request.session = Merb::CookieSession.new(cookies[_session_id_key], _session_secret_key)
0
- @original_session = request.session.read_cookie
0
- end
0
+ def setup_session
0
+ Merb.logger.info("Setting Up Cookie Store Sessions")
0
+ request.session = Merb::CookieSession.new(cookies[_session_id_key], _session_secret_key)
0
+ @original_session = request.session.read_cookie
0
+ end
0
 
0
- base.add_hook :after_dispatch do
0
- Merb.logger.info("Finalize Cookie Store Session")
0
- new_session = request.session.read_cookie
0
+ def finalize_session
0
+ Merb.logger.info("Finalize Cookie Store Session")
0
+ new_session = request.session.read_cookie
0
       
0
- if @original_session != new_session
0
- set_cookie(_session_id_key, new_session, Time.now + _session_expiry)
0
- end
0
+ if @original_session != new_session
0
+ set_cookie(_session_id_key, new_session, Time.now + _session_expiry)
0
       end
0
     end
0
 
...
8
9
10
11
12
13
14
15
16
17
18
 
 
 
 
 
 
19
20
21
22
23
24
25
 
 
 
26
 
27
28
29
...
8
9
10
 
 
 
 
 
 
 
 
11
12
13
14
15
16
17
 
 
 
 
 
 
18
19
20
21
22
23
24
25
0
@@ -8,22 +8,18 @@
0
     #
0
     # ==== Parameters
0
     # base<Class>:: The class to which the SessionMixin is mixed into.
0
- def self.included(base)
0
- base.add_hook :before_dispatch do
0
- Merb.logger.info("Setting up session")
0
- before = cookies[_session_id_key]
0
- request.session, cookies[_session_id_key] = Merb::MemCacheSession.persist(cookies[_session_id_key])
0
- @_fingerprint = Marshal.dump(request.session.data).hash
0
- @_new_cookie = cookies[_session_id_key] != before
0
- end
0
+ def setup_session
0
+ before = cookies[_session_id_key]
0
+ request.session, cookies[_session_id_key] = Merb::MemCacheSession.persist(cookies[_session_id_key])
0
+ @_fingerprint = Marshal.dump(request.session.data).hash
0
+ @_new_cookie = cookies[_session_id_key] != before
0
+ end
0
 
0
- base.add_hook :after_dispatch do
0
- Merb.logger.info("Finalize session")
0
- if @_fingerprint != Marshal.dump(request.session.data).hash
0
- ::Cache.put("session:#{request.session.session_id}", request.session.data)
0
- end
0
- set_cookie(_session_id_key, request.session.session_id, Time.now + _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
0
+ def finalize_session
0
+ if @_fingerprint != Marshal.dump(request.session.data).hash
0
+ ::Cache.put("session:#{request.session.session_id}", request.session.data)
0
       end
0
+ set_cookie(_session_id_key, request.session.session_id, Time.now + _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
0
     end
0
 
0
     # ==== Returns
...
7
8
9
10
11
12
13
14
15
16
 
 
 
 
 
 
17
18
19
20
21
 
 
 
22
23
24
...
7
8
9
 
 
 
 
 
 
 
10
11
12
13
14
15
16
 
 
 
 
17
18
19
20
21
22
0
@@ -7,18 +7,16 @@
0
     #
0
     # ==== Parameters
0
     # base<Class>:: The class to which the SessionMixin is mixed into.
0
- def self.included(base)
0
- base.add_hook :before_dispatch do
0
- Merb.logger.info("Setting up session")
0
- before = cookies[_session_id_key]
0
- request.session , cookies[_session_id_key] = Merb::MemorySession.persist(cookies[_session_id_key])
0
- @_new_cookie = cookies[_session_id_key] != before
0
- end
0
+ def setup_session
0
+ Merb.logger.info("Setting up session")
0
+ before = cookies[_session_id_key]
0
+ request.session , cookies[_session_id_key] = Merb::MemorySession.persist(cookies[_session_id_key])
0
+ @_new_cookie = cookies[_session_id_key] != before
0
+ end
0
       
0
- base.add_hook :after_dispatch do
0
- Merb.logger.info("Finalize session")
0
- set_cookie(_session_id_key, request.session.session_id, Time.now + _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
0
- end
0
+ def finalize_session
0
+ Merb.logger.info("Finalize session")
0
+ set_cookie(_session_id_key, request.session.session_id, Time.now + _session_expiry) if (@_new_cookie || request.session.needs_new_cookie)
0
     end
0
 
0
     # ==== Returns
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,63 +1 @@
0
-module Merb::Hook
0
-
0
- module ClassMethods
0
-
0
- # ==== Parameters
0
- # mod<Module>:: The module that Merb::Hook is being extended into.
0
- #
0
- # ==== Returns
0
- # Hash:: An empty hooks hash.
0
- def self.extended(mod)
0
- mod.cattr_accessor :_hooks
0
- mod._hooks = Hash.new {|h,k| h[k] = Dictionary.new {|h,k| h[k] = []}}
0
- end
0
-
0
- # Add a hook to the list of available hooks for the class.
0
- #
0
- # ==== Parameters
0
- # type<Object>:: The type of hook. Typically this would be a symbol.
0
- # obj<Proc, ~to_s>::
0
- # A block to evaluate (Proc) or a method name to call (~to_s) when the
0
- # hook is called.
0
- # &block:: A block that will be run when the hook is called if obj is nil.
0
- #
0
- # ==== Returns
0
- # Hash:: A Hash of all the registered hooks.
0
- def add_hook(type, obj = nil, &block)
0
- _hooks[type][self] << (obj || block)
0
- end
0
- end
0
-
0
- module InstanceMethods
0
- # Call all of the registered hooks for the passed in type by eval'ing any
0
- # Procs and sending any other types to the current object.
0
- #
0
- # ==== Parameters
0
- # type<Object>:: The registered type.
0
- #
0
- # ==== Returns
0
- # Array:: An array of all the registered hooks.
0
- def hook(type)
0
- _hooks[type].each do |klass, objs|
0
- if self.is_a?(klass)
0
- objs.each {|obj| obj.is_a?(Proc) ? instance_eval(&obj) : send(obj) }
0
- end
0
- end
0
- end
0
- end
0
-
0
-end
0
-
0
-class Class
0
-
0
- # Make the class hookable, by giving it .add_hook and #hook.
0
- #
0
- # ==== Returns
0
- # Nil
0
- def is_hookable
0
- self.send(:extend, Merb::Hook::ClassMethods)
0
- self.send(:include, Merb::Hook::InstanceMethods)
0
- nil
0
- end
0
-end
...
1
 
2
3
4
...
14
15
16
17
 
 
 
 
18
19
20
...
1
2
3
4
5
...
15
16
17
 
18
19
20
21
22
23
24
0
@@ -1,4 +1,5 @@
0
 require 'swiftcore/evented_mongrel'
0
+require 'merb-core/rack/handler/mongrel'
0
 module Merb
0
   module Rack
0
 
0
@@ -14,7 +15,10 @@
0
       # :app<String>>:: The application name.
0
       def self.start(opts={})
0
         Merb.logger.info("Using EventedMongrel adapter: #{opts.inspect}")
0
- super(opts)
0
+ Merb.logger.flush
0
+ server = ::Mongrel::HttpServer.new(opts[:host], opts[:port].to_i)
0
+ server.register('/', ::Merb::Rack::Handler::Mongrel.new(opts[:app]))
0
+ server.run.join
0
       end
0
     end
0
   end
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@
0
       # :port<Fixnum>:: The port Mongrel should bind to.
0
       # :app<String>>:: The application name.
0
       def self.start(opts={})
0
- Merb.logger.info("Using Mongrel adapter") if self == Merb::Rack::Mongrel
0
+ Merb.logger.info("Using Mongrel adapter")
0
         Merb.logger.flush
0
         server = ::Mongrel::HttpServer.new(opts[:host], opts[:port])
0
         server.register('/', ::Merb::Rack::Handler::Mongrel.new(opts[:app]))
...
16
17
18
 
 
 
19
20
21
...
16
17
18
19
20
21
22
23
24
0
@@ -16,6 +16,9 @@
0
       def self.start(opts={})
0
         Merb.logger.info("Using Thin adapter")
0
         Merb.logger.flush
0
+ if opts[:host].include?('/')
0
+ opts[:host] = "#{opts[:host]}-#{opts[:port]}"
0
+ end
0
         server = ::Thin::Server.new(opts[:host], opts[:port], opts[:app])
0
         ::Thin::Logging.silent = true
0
         server.start!
...
1
2
3
4
5
6
...
 
1
 
2
3
4
0
@@ -1,6 +1,4 @@
0
-require 'mongrel'
0
 require 'stringio'
0
-
0
 class Mongrel::HttpResponse
0
   NO_CLOSE_STATUS_FORMAT = "HTTP/1.1 %d %s\r\n".freeze
0
   def send_status_no_connection_close(content_length=@body.length)
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
26
27
28
 
 
 
 
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
0
@@ -26,31 +26,7 @@
0
     calling { dispatch_to(Merb::Test::Fixtures::Controllers::Base, :bat) }.
0
       should raise_error(Merb::ControllerExceptions::ActionNotFound)
0
   end
0
-
0
- it "should support hooks before dispatch with a proc" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::BeforeHook, :index)
0
- controller.body.should == "Proc"
0
- end
0
 
0
- it "should support hooks before dispatch with a proc" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::BeforeHookInherit, :index)
0
- controller.body.should == "Proc"
0
- end
0
-
0
- it "should support hooks before dispatch with a symbol (and inherit)" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::BeforeHookSymbol, :index)
0
- controller.body.should == "Proc Symbol"
0
- end
0
-
0
- it "should support hooks after dispatch with a proc" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::AfterHook, :index)
0
- controller.body.should == "Proc"
0
- end
0
-
0
- it "should support hooks after dispatch with a symbol (and inherit)" do
0
- controller = dispatch_to(Merb::Test::Fixtures::Controllers::AfterHookSymbol, :index)
0
- controller.body.should == "Proc Symbol"
0
- end
0
     
0
 end
...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
41
0
@@ -37,60 +37,6 @@
0
       hide_action :hidden
0
     end
0
 
0
- class BeforeHook < Testing
0
- add_hook(:before_dispatch) do
0
- @stuff = "Proc"
0
- end
0
-
0
- def index
0
- @stuff
0
- end
0
- end
0
-
0
- class BeforeHookInherit < BeforeHook
0
-
0
- def index
0
- @stuff
0
- end
0
- end
0
-
0
- class BeforeHookSymbol < BeforeHook
0
- add_hook :before_dispatch, :stuff
0
-
0
- def index
0
- "#{@stuff} #{@stuff2}"
0
- end
0
-
0
- private
0
-
0
- def stuff
0
- @stuff2 = "Symbol"
0
- end
0
- end
0
-
0
- class AfterHook < Testing
0
- add_hook(:after_dispatch) do
0
- @body = "Proc"
0
- end
0
-
0
- def index
0
- ""
0
- end
0
- end
0
-
0
- class AfterHookSymbol < AfterHook
0
- add_hook(:after_dispatch, :stuff)
0
-
0
- def index
0
- ""
0
- end
0
-
0
- private
0
-
0
- def stuff
0
- @body += " Symbol"
0
- end
0
- end
0
   end
0
 end

Comments

    No one has commented yet.