Class: 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
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 |
#headers ⇒ Object
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_action ⇒ Object
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_class ⇒ Object
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 |