merb 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +66 -31
- data/Rakefile +3 -1
- data/bin/merb +47 -13
- data/examples/app_skeleton/Rakefile +4 -3
- data/examples/app_skeleton/dist/app/helpers/global_helper.rb +6 -0
- data/examples/app_skeleton/dist/conf/merb.yml +11 -0
- data/examples/app_skeleton/dist/conf/mup.conf +5 -0
- data/examples/app_skeleton/dist/conf/router.rb +1 -3
- data/examples/app_skeleton/scripts/merb_stop +10 -2
- data/examples/sample_app/Rakefile +3 -3
- data/examples/sample_app/dist/app/controllers/files.rb +3 -3
- data/examples/sample_app/dist/app/controllers/posts.rb +25 -23
- data/examples/sample_app/dist/app/controllers/test.rb +7 -3
- data/examples/sample_app/dist/app/helpers/global_helper.rb +7 -0
- data/examples/sample_app/dist/app/helpers/posts_helper.rb +4 -0
- data/examples/sample_app/dist/app/views/layout/application.herb +5 -4
- data/examples/sample_app/dist/app/views/layout/foo.herb +1 -1
- data/examples/sample_app/dist/app/views/posts/new.herb +9 -2
- data/examples/sample_app/dist/app/views/shared/_test.herb +1 -0
- data/examples/sample_app/dist/conf/merb.yml +7 -7
- data/examples/sample_app/dist/conf/merb_init.rb +8 -1
- data/examples/sample_app/dist/conf/mup.conf +5 -11
- data/examples/sample_app/dist/conf/router.rb +1 -1
- data/examples/sample_app/dist/public/test.html +5 -0
- data/examples/sample_app/dist/schema/migrations/002_add_sessions_table.rb +1 -1
- data/examples/sample_app/dist/schema/schema.rb +1 -1
- data/examples/sample_app/log/merb.4000.pid +1 -0
- data/lib/merb.rb +35 -17
- data/lib/merb/core_ext.rb +2 -0
- data/lib/merb/{merb_class_extensions.rb → core_ext/merb_class.rb} +42 -0
- data/lib/merb/core_ext/merb_enumerable.rb +7 -0
- data/lib/merb/{merb_utils.rb → core_ext/merb_hash.rb} +1 -78
- data/lib/merb/core_ext/merb_kernel.rb +16 -0
- data/lib/merb/core_ext/merb_module.rb +10 -0
- data/lib/merb/core_ext/merb_numeric.rb +20 -0
- data/lib/merb/core_ext/merb_object.rb +6 -0
- data/lib/merb/core_ext/merb_string.rb +40 -0
- data/lib/merb/core_ext/merb_symbol.rb +12 -0
- data/lib/merb/merb_constants.rb +18 -0
- data/lib/merb/merb_controller.rb +150 -76
- data/lib/merb/{session/merb_drb_server.rb → merb_drb_server.rb} +13 -46
- data/lib/merb/merb_exceptions.rb +4 -0
- data/lib/merb/merb_handler.rb +29 -17
- data/lib/merb/merb_request.rb +95 -0
- data/lib/merb/merb_upload_handler.rb +46 -0
- data/lib/merb/merb_upload_progress.rb +48 -0
- data/lib/merb/merb_view_context.rb +46 -0
- data/lib/merb/merb_yaml_store.rb +31 -0
- data/lib/merb/mixins/basic_authentication_mixin.rb +2 -2
- data/lib/merb/mixins/controller_mixin.rb +24 -75
- data/lib/merb/mixins/erubis_capture_mixin.rb +84 -0
- data/lib/merb/mixins/javascript_mixin.rb +103 -19
- data/lib/merb/mixins/merb_status_codes.rb +59 -0
- data/lib/merb/mixins/render_mixin.rb +114 -40
- data/lib/merb/mixins/responder_mixin.rb +2 -1
- data/lib/merb/session/merb_ar_session.rb +120 -0
- data/lib/merb/session/merb_drb_session.rb +0 -6
- data/lib/merb/vendor/paginator/paginator.rb +102 -99
- metadata +44 -8
- data/examples/sample_app/script/startdrb +0 -8
- data/lib/merb/session/merb_session.rb +0 -64
- data/lib/mutex_hotfix.rb +0 -34
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
module Merb
|
3
|
-
module SessionMixin
|
4
|
-
|
5
|
-
def setup_session
|
6
|
-
MERB_LOGGER.info("Setting up session")
|
7
|
-
@session = Merb::Session.persist(cookies)
|
8
|
-
@fingerprint_before = Marshal.dump(@session).hash
|
9
|
-
end
|
10
|
-
|
11
|
-
def finalize_session
|
12
|
-
MERB_LOGGER.info("Finalize session")
|
13
|
-
unless Marshal.dump(@session).hash == @fingerprint_before
|
14
|
-
@session.save
|
15
|
-
end
|
16
|
-
@headers['Set-Cookie'] = @cookies.map { |k,v| "#{k}=#{escape(v)}; path=/" if v != @k[k] } - [nil]
|
17
|
-
end
|
18
|
-
|
19
|
-
# accessor for @session. Please use session and
|
20
|
-
# never @session directly.
|
21
|
-
def session
|
22
|
-
@session
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
class Session < ::ActiveRecord::Base
|
29
|
-
serialize :data
|
30
|
-
|
31
|
-
def []=(k, v) # :nodoc:
|
32
|
-
self.data[k] = v
|
33
|
-
end
|
34
|
-
def [](k) # :nodoc:
|
35
|
-
self.data[k] rescue nil
|
36
|
-
end
|
37
|
-
|
38
|
-
RAND_CHARS = [*'A'..'Z'] + [*'0'..'9'] + [*'a'..'z']
|
39
|
-
|
40
|
-
# Generates a new session ID and creates a row for the new session in the database.
|
41
|
-
def self.generate cookies
|
42
|
-
rand_max = RAND_CHARS.size
|
43
|
-
sid = (0...32).inject("") { |ret,_| ret << RAND_CHARS[rand(rand_max)] }
|
44
|
-
sess = Merb::Session.create(:sess_id => sid, :data => MerbHash[])
|
45
|
-
cookies[:sess_id] = sess.sess_id
|
46
|
-
sess
|
47
|
-
end
|
48
|
-
|
49
|
-
# Gets the existing session based on the <tt>camping_sid</tt> available in cookies.
|
50
|
-
# If none is found, generates a new session.
|
51
|
-
def self.persist cookies
|
52
|
-
if cookies[:sess_id]
|
53
|
-
session = Merb::Session.find_by_sess_id cookies[:sess_id]
|
54
|
-
end
|
55
|
-
unless session
|
56
|
-
session = Merb::Session.generate cookies
|
57
|
-
end
|
58
|
-
session
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
|
data/lib/mutex_hotfix.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
|
-
# monkey patch Mutex so it does not leak memory.
|
4
|
-
class Mutex
|
5
|
-
|
6
|
-
def lock
|
7
|
-
while (Thread.critical = true; @locked)
|
8
|
-
@waiting.unshift Thread.current
|
9
|
-
Thread.stop
|
10
|
-
end
|
11
|
-
@locked = true
|
12
|
-
Thread.critical = false
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
def unlock
|
17
|
-
return unless @locked
|
18
|
-
Thread.critical = true
|
19
|
-
@locked = false
|
20
|
-
begin
|
21
|
-
t = @waiting.pop
|
22
|
-
t.wakeup if t
|
23
|
-
rescue ThreadError
|
24
|
-
retry
|
25
|
-
end
|
26
|
-
Thread.critical = false
|
27
|
-
begin
|
28
|
-
t.run if t
|
29
|
-
rescue ThreadError
|
30
|
-
end
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|