Class: Tofu::Session
- Inherits:
-
Object
- Object
- Tofu::Session
- Includes:
- MonitorMixin
- Defined in:
- lib/tofu.rb,
lib/tofu.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hint ⇒ Object
Returns the value of attribute hint.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
Instance Method Summary collapse
- #dispatch_event(context) ⇒ Object
- #do_GET(context) ⇒ Object
- #do_inner_html(context) ⇒ Object
- #entry(tofu) ⇒ Object
- #expired? ⇒ Boolean
- #expires ⇒ Object
- #fetch(ref) ⇒ Object
- #hint_expires ⇒ Object
-
#initialize(bartender, hint = nil) ⇒ Session
constructor
A new instance of Session.
- #lookup_view(context) ⇒ Object
- #renew ⇒ Object
- #service(context) ⇒ Object
Constructor Details
#initialize(bartender, hint = nil) ⇒ Session
Returns a new instance of Session.
15 16 17 18 19 20 21 |
# File 'lib/tofu.rb', line 15 def initialize(, hint=nil) super() @session_id = SecureRandom.uuid @contents = {} @hint = hint renew end |
Instance Attribute Details
#hint ⇒ Object
Returns the value of attribute hint.
23 24 25 |
# File 'lib/tofu.rb', line 23 def hint @hint end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
22 23 24 |
# File 'lib/tofu.rb', line 22 def session_id @session_id end |
Instance Method Details
#dispatch_event(context) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/tofu.rb', line 58 def dispatch_event(context) params = context.req_params tofu_id ,= params['tofu_id'] tofu = fetch(tofu_id) return unless tofu tofu.send_request(context, context.req_params) end |
#do_GET(context) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/tofu.rb', line 50 def do_GET(context) dispatch_event(context) tofu = lookup_view(context) body = tofu ? tofu.to_html(context) : '' context.res_header('content-type', 'text/html; charset=utf-8') context.res_body(body) end |
#do_inner_html(context) ⇒ Object
575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/tofu.rb', line 575 def do_inner_html(context) params = context.req_params tofu_id ,= params['tofu_inner_id'] return false unless tofu_id tofu = fetch(tofu_id) body = tofu ? tofu.to_inner_html(context) : '' context.res_header('content-type', 'text/html; charset=utf-8') context.res_body(body) throw(:tofu_done) end |
#entry(tofu) ⇒ Object
70 71 72 73 74 |
# File 'lib/tofu.rb', line 70 def entry(tofu) synchronize do @contents[tofu.tofu_id] = tofu end end |
#expired? ⇒ Boolean
46 47 48 |
# File 'lib/tofu.rb', line 46 def expired? @expires && Time.now > @expires end |
#expires ⇒ Object
34 35 36 |
# File 'lib/tofu.rb', line 34 def expires Time.now + 24 * 60 * 60 end |
#fetch(ref) ⇒ Object
76 77 78 |
# File 'lib/tofu.rb', line 76 def fetch(ref) @contents[ref] end |
#hint_expires ⇒ Object
38 39 40 |
# File 'lib/tofu.rb', line 38 def hint_expires Time.now + 60 * 24 * 60 * 60 end |
#lookup_view(context) ⇒ Object
66 67 68 |
# File 'lib/tofu.rb', line 66 def lookup_view(context) nil end |
#renew ⇒ Object
42 43 44 |
# File 'lib/tofu.rb', line 42 def renew @expires = expires end |
#service(context) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/tofu.rb', line 25 def service(context) case context.req_method when 'GET', 'POST', 'HEAD' do_GET(context) else context.res_method_not_allowed end end |