Class: Ki::BaseRequest
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Ki::BaseRequest
- Includes:
- Middleware::Helpers::FormatOf
- Defined in:
- lib/ki/base_request.rb
Instance Method Summary collapse
- #admin? ⇒ Boolean
- #doc? ⇒ Boolean
- #headers ⇒ Object
- #json? ⇒ Boolean
- #root? ⇒ Boolean
- #to_action ⇒ Object
- #to_ki_model_class ⇒ Object
Methods included from Middleware::Helpers::FormatOf
Instance Method Details
#admin? ⇒ Boolean
13 14 15 |
# File 'lib/ki/base_request.rb', line 13 def admin? path == '/instadmin' end |
#doc? ⇒ Boolean
9 10 11 |
# File 'lib/ki/base_request.rb', line 9 def doc? path == '/instadoc' end |
#headers ⇒ Object
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
17 18 19 |
# File 'lib/ki/base_request.rb', line 17 def json? content_type == 'application/json' || format_of(path) == 'json' end |
#root? ⇒ Boolean
5 6 7 |
# File 'lib/ki/base_request.rb', line 5 def root? path == '/' end |
#to_action ⇒ Object
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_class ⇒ Object
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 |