Module: Mountapi::Response::Base::InstanceMethods
- Defined in:
- lib/mountapi/response/base.rb
Instance Method Summary collapse
- #default_schema ⇒ Object
-
#response ⇒ Object
Since we return a mountapi response they must have a custom rack response to enable customizing.
- #status ⇒ Object
- #to_json ⇒ Object
-
#to_rack ⇒ Object
Use the existing (or default) rack response.
- #validate(definitions) ⇒ Object
Instance Method Details
#default_schema ⇒ Object
45 46 47 |
# File 'lib/mountapi/response/base.rb', line 45 def default_schema Mountapi::Response.default_schema end |
#response ⇒ Object
Since we return a mountapi response they must have a custom rack response to enable customizing
29 30 31 |
# File 'lib/mountapi/response/base.rb', line 29 def response @response ||= Rack::Response.new([]) end |
#status ⇒ Object
24 25 26 |
# File 'lib/mountapi/response/base.rb', line 24 def status self.class.get_status end |
#to_json ⇒ Object
41 42 43 |
# File 'lib/mountapi/response/base.rb', line 41 def to_json payload.to_json end |
#to_rack ⇒ Object
Use the existing (or default) rack response
34 35 36 37 38 39 |
# File 'lib/mountapi/response/base.rb', line 34 def to_rack response.status = status response.write(to_json) response.set_header("content-type", "application/json") response.finish end |
#validate(definitions) ⇒ Object
49 50 51 52 |
# File 'lib/mountapi/response/base.rb', line 49 def validate(definitions) errors = Schema::Validator.call(definitions[status].to_json_schema, payload) errors.empty? || raise(Error::InvalidResponse, errors) end |