diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-06-20 16:57:59 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-06-20 16:57:59 +0200 |
commit | f8922272bbf9816dec7fe4c57002afb54d353f50 (patch) | |
tree | debf9d5df144b033ed6fdafe3c6ccbe37396c519 | |
parent | c4fc070d4080bc609dfaba0db9e2e493cbffd1ac (diff) | |
download | zorglub-f8922272bbf9816dec7fe4c57002afb54d353f50.zip zorglub-f8922272bbf9816dec7fe4c57002afb54d353f50.tar.gz |
simple never cleaned in memory session data management
-rw-r--r-- | lib/zorglub/config.rb | 3 | ||||
-rw-r--r-- | lib/zorglub/node.rb | 11 | ||||
-rw-r--r-- | lib/zorglub/session.rb | 26 |
3 files changed, 29 insertions, 11 deletions
diff --git a/lib/zorglub/config.rb b/lib/zorglub/config.rb index 70fdfcc..3916ac7 100644 --- a/lib/zorglub/config.rb +++ b/lib/zorglub/config.rb @@ -8,7 +8,8 @@ module Zorglub :engine => nil, :view_dir => 'view', :layout_dir => 'layout', - :default_layout => 'default' + :default_layout => 'default', + :session_on => false } @engines = { } class << self diff --git a/lib/zorglub/node.rb b/lib/zorglub/node.rb index 2e080ca..14808ae 100644 --- a/lib/zorglub/node.rb +++ b/lib/zorglub/node.rb @@ -33,8 +33,6 @@ module Zorglub action = {:engine=>engine,:layout=>layout,:view=>File.join(r,meth),:method=>meth,:args=>args} node = self.new Rack::Request.new(env), Rack::Response.new, action return error_404 node if not node.respond_to? meth - # TODO - # - session node.realize end # @@ -58,9 +56,8 @@ module Zorglub # def realize @content = self.send @action[:method], *@action[:args] - e = Config.engine_proc @action[:engine] - v = view - l = layout + e, v, l = Config.engine_proc(@action[:engine]), view, layout + # TODO compile and cache @content = e.call v, self if e and File.exists? v @content = e.call l, self if e and File.exists? l response.write @content @@ -90,6 +87,10 @@ module Zorglub self.class.r end # + def session + @session ||= Session.new( Config.session_on ? @request.cookies : {} ) + end + # def r File.join map, @action[:method] end diff --git a/lib/zorglub/session.rb b/lib/zorglub/session.rb index b119e2b..da30deb 100644 --- a/lib/zorglub/session.rb +++ b/lib/zorglub/session.rb @@ -4,13 +4,29 @@ require 'securerandom' # module Zorglub # - Config.session_id_length ||= 64 - Config.session_ttl ||= (60 * 60 * 24 * 5) - # class Session # - def gen_session_id - SecureRandom.hex Config.session_id_length + @session_key = 'zorglub.sid' + @session_data = {} + class << self + attr_reader :session_key, :session_data + end + # + def initialize cookies + @sid = cookies[self.class.session_key] + @data = self.class.session_data[@sid]||={} + end + # + def exists? + not @sid.nil? + end + # + def [] idx + @data[idx] + end + # + def []= idx, v + @data[idx] = v end # end |