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



15
16
17
# File 'lib/ki/base_request.rb', line 15

def admin?
  path == '/instadmin'
end

#doc?Boolean



11
12
13
# File 'lib/ki/base_request.rb', line 11

def doc?
  path == '/instadoc'
end

#headersObject



23
24
25
26
27
28
# File 'lib/ki/base_request.rb', line 23

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

#json?Boolean



19
20
21
# File 'lib/ki/base_request.rb', line 19

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

#root?Boolean



7
8
9
# File 'lib/ki/base_request.rb', line 7

def root?
  path == '/'
end

#to_actionObject



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

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

#to_ki_model_classObject



30
31
32
# File 'lib/ki/base_request.rb', line 30

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