Class: Lame::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject

Returns the value of attribute path.



38
39
40
# File 'lib/main.rb', line 38

def path
  @path
end

#queryObject

Returns the value of attribute query.



38
39
40
# File 'lib/main.rb', line 38

def query
  @query
end

Instance Method Details

#call(env) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/main.rb', line 62

def call(env)
  env[:query] = self.parse_query_string(env['QUERY_STRING'])
  env[:path] = self.parse_uri(env['PATH_INFO'])
  resp = response(env)
  status_code = resp[:status_code] || 200
  content_type = resp[:content_type] || "text/plain"
  [status_code, {"Content-Type" => content_type}, [resp[:body]]]
end

#initailize(env) ⇒ Object



40
41
42
# File 'lib/main.rb', line 40

def initailize(env)
  @env = env
end

#parse_query_string(query_string) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/main.rb', line 53

def parse_query_string(query_string)
  begin
    params = query_string.split('&').inject({}) {|h,(k,v)| h[k.split('=')[0].intern] = CGI.unescape(k.split('=')[1]); h}
  rescue NoMethodError
    params = Hash.new
  end
  return params
end

#parse_uri(request_path) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/main.rb', line 44

def parse_uri(request_path)
  begin
    uri = (request_path.split("/").collect {|r| r.intern unless r.empty?}).compact
  rescue NoMethodError
    uri = Hash.new
  end
  return uri
end