Class: SnapImage::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- SnapImage::Response
- Defined in:
- lib/snapimage/rack/response.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#json ⇒ Object
Returns the value of attribute json.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
- #set_bad_request ⇒ Object
- #set_file_too_large ⇒ Object
- #set_internal_server_error ⇒ Object
- #set_invalid_directory ⇒ Object
- #set_invalid_filename ⇒ Object
- #set_success(info = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 |
# File 'lib/snapimage/rack/response.rb', line 5 def initialize( = {}) @content_type = [:content_type] || "text/json" @template = [:template] || "{{json}}" @json = {} super() end |
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
3 4 5 |
# File 'lib/snapimage/rack/response.rb', line 3 def content_type @content_type end |
#json ⇒ Object
Returns the value of attribute json.
3 4 5 |
# File 'lib/snapimage/rack/response.rb', line 3 def json @json end |
#template ⇒ Object
Returns the value of attribute template.
3 4 5 |
# File 'lib/snapimage/rack/response.rb', line 3 def template @template end |
Instance Method Details
#finish ⇒ Object
37 38 39 40 41 |
# File 'lib/snapimage/rack/response.rb', line 37 def finish write(@template.gsub(/{{json}}/, @json.to_json)) self["Content-Type"] = @content_type super end |
#set_bad_request ⇒ Object
17 18 19 |
# File 'lib/snapimage/rack/response.rb', line 17 def set_bad_request @json = { status_code: 400, message: "Bad Request" } end |
#set_file_too_large ⇒ Object
29 30 31 |
# File 'lib/snapimage/rack/response.rb', line 29 def set_file_too_large @json = { status_code: 405, message: "File Too Large" } end |
#set_internal_server_error ⇒ Object
33 34 35 |
# File 'lib/snapimage/rack/response.rb', line 33 def set_internal_server_error @json = { status_code: 500, message: "Internal Server Error" } end |
#set_invalid_directory ⇒ Object
25 26 27 |
# File 'lib/snapimage/rack/response.rb', line 25 def set_invalid_directory @json = { status_code: 404, message: "Invalid Directory" } end |
#set_invalid_filename ⇒ Object
21 22 23 |
# File 'lib/snapimage/rack/response.rb', line 21 def set_invalid_filename @json = { status_code: 403, message: "Invalid Filename" } end |
#set_success(info = {}) ⇒ Object
12 13 14 15 |
# File 'lib/snapimage/rack/response.rb', line 12 def set_success(info = {}) info[:message] ||= "Success" @json = { status_code: 200 }.merge(info) end |