Class: OMF::Web::Rack::UpdateHandler

Inherits:
Base::LObject
  • Object
show all
Defined in:
lib/omf-web/rack/update_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ UpdateHandler

Returns a new instance of UpdateHandler.



10
11
# File 'lib/omf-web/rack/update_handler.rb', line 10

def initialize(opts = {})
end

Instance Method Details

#call(env) ⇒ Object



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
# File 'lib/omf-web/rack/update_handler.rb', line 14

def call(env)
  req = ::Rack::Request.new(env)
  begin
    sid = req.params['sid']
    unless sid
      raise MissingArgumentException.new "Called update without a 'sid' (#{req.inspect})"
    end
    Thread.current["sessionID"] = sid
    
    ds_id = req.path_info[1 .. -1].to_sym
    ds_proxy = OMF::Web::DataSourceProxy[ds_id]
    unless ds_proxy
      raise MissingArgumentException.new "Can't find data source proxy '#{ds_id}'"
    end
    body, headers = ds_proxy.on_update(req)
    
    # comp_path = id.split(':')
    # h = OMF::Web::SessionStore.find_tab_from_path(comp_path)
    # Thread.current["sessionID"] = h[:sid]
    # tab_inst = h[:tab_inst]
    # sub_path = h[:sub_path]
    #body, headers = tab_inst.on_update(req, sub_path.dup)
  rescue MissingArgumentException => mex
    debug mex
    return [412, {"Content-Type" => 'text'}, [mex.to_s]]
  rescue Exception => ex
    error ex
    debug ex.to_s + "\n\t" + ex.backtrace.join("\n\t")
    return [500, {"Content-Type" => 'text'}, [ex.to_s]]
  end
  
  if headers.kind_of? String
    headers = {"Content-Type" => headers}
  end
  [200, headers, [body]] 
end