Class: Lamed::Controller

Inherits:
Mustache
  • Object
show all
Includes:
Helper, Model, Rack
Defined in:
lib/lamed/controller.rb

Instance Method Summary collapse

Methods included from Helper

#camelize_path, #camelize_string, #class_to_path, #mysql_time, #sorted_array, #sorted_hash, #sorted_weighted_hash, #symbolize_hash_keys, #uncamelize_path, #uncamelize_string

Instance Method Details

#callObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/lamed/controller.rb', line 52

def call
  #@env = env unless defined?(@env)
  env[:query] = self.params(env['QUERY_STRING'])
  env[:path] = self.uri(env['SCRIPT_NAME'])
  response
  resp = req_params
  status_code = resp[:status_code] || 200
  content_type = resp[:content_type] || "text/html"
  [status_code, {"Content-Type" => content_type}, [resp[:body]]]
end

#content_type(content_type) ⇒ Object



19
20
21
# File 'lib/lamed/controller.rb', line 19

def content_type(content_type)
  req_params[:content_type] = content_type
end

#params(query_string) ⇒ Object

Build param symbols from the query string



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lamed/controller.rb', line 38

def params(query_string)
  begin
    params_prime = query_string.split('&').inject({}) { |h,(k,v)|
      values = k.split('=')
      # Drop any query params that have blank values
      h[values[0].downcase.intern] = (CGI.unescape(values[1])).downcase if values.length == 2 
      h
    }
  rescue NoMethodError => e
    params_prime = Hash.new
  end
  params_prime
end

#req_paramsObject



15
16
17
# File 'lib/lamed/controller.rb', line 15

def req_params
  env
end

#request(*args) ⇒ Object

This is just a reminder that I need to add something here



64
65
# File 'lib/lamed/controller.rb', line 64

def request(*args)
end

#responseObject



67
68
69
70
# File 'lib/lamed/controller.rb', line 67

def response
 req_params[:body] = self.render
 #return @req_params
end

#self_path(str) ⇒ Object



11
12
13
# File 'lib/lamed/controller.rb', line 11

def self_path(str)
  @self_path = str
end

#uri(request_path) ⇒ Object

Find the uri’s as and array of symbols from the request_path



28
29
30
31
32
33
34
35
# File 'lib/lamed/controller.rb', line 28

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

#user_agentObject



23
24
25
# File 'lib/lamed/controller.rb', line 23

def user_agent
  req_params['HTTP_USER_AGENT']
end