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

#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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ki/base_request.rb', line 25

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



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

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