Module: Gnarly::Status
- Included in:
- Application, Provides, Understands
- Defined in:
- lib/gnarly/status.rb
Instance Method Summary collapse
- #created(location) ⇒ Object
- #default_content_type ⇒ Object
- #internal_server_error(body = "Internal Server Error", mime = "text/plain") ⇒ Object
- #method_not_allowed(allow, body = "Method Not Allowed", mime = "text/plain") ⇒ Object
- #not_acceptable(acceptable = nil, body = nil, mime = "text/plain") ⇒ Object
- #not_found(body = "Not Found", mime = "text/plain") ⇒ Object
- #ok(body, mime = nil, charset = nil) ⇒ Object
- #pop_default_content_type ⇒ Object
- #push_default_content_type(mime) ⇒ Object
- #unsupported_media_type(body = "Unsupported Media Type", mime = "text/plain") ⇒ Object
Instance Method Details
#created(location) ⇒ Object
25 26 27 28 |
# File 'lib/gnarly/status.rb', line 25 def created(location) headers = {"Location" => location, "Content-type" => "text/plain"} [201, headers, [""]] end |
#default_content_type ⇒ Object
14 15 16 |
# File 'lib/gnarly/status.rb', line 14 def default_content_type() @default_content_types.last if @default_content_types end |
#internal_server_error(body = "Internal Server Error", mime = "text/plain") ⇒ Object
51 52 53 |
# File 'lib/gnarly/status.rb', line 51 def internal_server_error(body="Internal Server Error", mime="text/plain") [500, {"Content-type" => mime}, [body]] end |
#method_not_allowed(allow, body = "Method Not Allowed", mime = "text/plain") ⇒ Object
34 35 36 37 38 |
# File 'lib/gnarly/status.rb', line 34 def method_not_allowed(allow, body="Method Not Allowed", mime="text/plain") [405, {"Content-type" => mime, "Allow" => allow}, [body]] end |
#not_acceptable(acceptable = nil, body = nil, mime = "text/plain") ⇒ Object
40 41 42 43 44 45 |
# File 'lib/gnarly/status.rb', line 40 def not_acceptable(acceptable=nil, body=nil, mime="text/plain") body = "" unless body [406, {"Content-type" => mime}, [body]] end |
#not_found(body = "Not Found", mime = "text/plain") ⇒ Object
30 31 32 |
# File 'lib/gnarly/status.rb', line 30 def not_found(body="Not Found", mime="text/plain") [404, {"Content-type" => mime}, [body]] end |
#ok(body, mime = nil, charset = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/gnarly/status.rb', line 18 def ok(body, mime=nil, charset=nil) mime = default_content_type unless mime charset = body.encoding.name.downcase unless charset headers = mime ? {"Content-type" => "#{mime}; charset=#{charset}"} : {} [200, headers, [body]] end |
#pop_default_content_type ⇒ Object
10 11 12 |
# File 'lib/gnarly/status.rb', line 10 def pop_default_content_type() @default_content_types.pop if @default_content_types end |
#push_default_content_type(mime) ⇒ Object
6 7 8 |
# File 'lib/gnarly/status.rb', line 6 def push_default_content_type(mime) (@default_content_types ||= []).push mime end |
#unsupported_media_type(body = "Unsupported Media Type", mime = "text/plain") ⇒ Object
47 48 49 |
# File 'lib/gnarly/status.rb', line 47 def unsupported_media_type(body="Unsupported Media Type", mime="text/plain") [415, {"Content-type" => mime}, [body]] end |