class Tofu::Session

Attributes

hint[RW]
session_id[R]

Public Class Methods

new(bartender, hint=nil) click to toggle source
Calls superclass method
# File lib/tofu.rb, line 15
def initialize(bartender, hint=nil)
  super()
  @session_id = SecureRandom.uuid
  @contents = {}
  @hint = hint
  renew
end

Public Instance Methods

dispatch_event(context) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/tofu.rb, line 70
def entry(tofu)
  synchronize do
    @contents[tofu.tofu_id] = tofu
  end
end
expired?() click to toggle source
# File lib/tofu.rb, line 46
def expired?
  @expires && Time.now > @expires
end
expires() click to toggle source
# File lib/tofu.rb, line 34
def expires
  Time.now + 24 * 60 * 60
end
fetch(ref) click to toggle source
# File lib/tofu.rb, line 76
def fetch(ref)
  @contents[ref]
end
hint_expires() click to toggle source
# File lib/tofu.rb, line 38
def hint_expires
  Time.now + 60 * 24 * 60 * 60
end
lookup_view(context) click to toggle source
# File lib/tofu.rb, line 66
def lookup_view(context)
  nil
end
renew() click to toggle source
# File lib/tofu.rb, line 42
def renew
  @expires = expires
end
service(context) click to toggle source
# 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