Class: Ki::BaseRequest

Inherits:
Rack::Request
  • Object
show all
Includes:
Middleware::Helpers::FormatOf
Defined in:
lib/ki/base_request.rb

Instance Method Summary collapse

Methods included from Middleware::Helpers::FormatOf

#format_of

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/ki/base_request.rb', line 13

def admin?
  path == '/instadmin'
end

#doc?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/ki/base_request.rb', line 9

def doc?
  path == '/instadoc'
end

#headersObject



21
22
23
24
25
26
# File 'lib/ki/base_request.rb', line 21

def headers
  Hash[*env.select { |k, _v| k.start_with? 'HTTP_' }
    .collect { |k, v| [k.sub(/^HTTP_/, ''), v] }
    .sort
    .flatten]
end

#json?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/ki/base_request.rb', line 17

def json?
  content_type == 'application/json' || format_of(path) == 'json'
end

#root?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/ki/base_request.rb', line 5

def root?
  path == '/'
end

#to_actionObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ki/base_request.rb', line 32

def to_action
  case request_method
  when 'GET'
    :find
  when 'POST'
    :create
  when 'PUT'
    :update
  when 'DELETE'
    :delete
  when 'SEARCH'
    :find
  else
    fail 'unkown action'
  end
end

#to_ki_model_classObject



28
29
30
# File 'lib/ki/base_request.rb', line 28

def to_ki_model_class
  path.to_s.gsub('/', '').gsub(format_of(path), '').gsub('.', '').to_class
end