Class: Api::ResponseBuilder::Main
- Inherits:
-
Object
- Object
- Api::ResponseBuilder::Main
- Defined in:
- lib/api/response_builder/main.rb
Overview
Class which helps in building whole api response
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#params ⇒ Object
Returns the value of attribute params.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(resource, config = {}, params = {}) ⇒ Main
constructor
A new instance of Main.
- #prepare_response ⇒ Object
- #set_response ⇒ Object
Constructor Details
#initialize(resource, config = {}, params = {}) ⇒ Main
Returns a new instance of Main.
11 12 13 14 15 16 17 |
# File 'lib/api/response_builder/main.rb', line 11 def initialize(resource, config = {}, params = {}) @resource = resource @config = config @response = {} @params = params set_response end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/api/response_builder/main.rb', line 6 def config @config end |
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/api/response_builder/main.rb', line 6 def params @params end |
#resource ⇒ Object
Returns the value of attribute resource.
6 7 8 |
# File 'lib/api/response_builder/main.rb', line 6 def resource @resource end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/api/response_builder/main.rb', line 6 def response @response end |
Instance Method Details
#prepare_response ⇒ Object
31 32 33 34 |
# File 'lib/api/response_builder/main.rb', line 31 def prepare_response status_msg = ::Api::ResponseBuilder::Status.new(resource, config). @response = status_msg.present? ? status_msg : {} end |
#set_response ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/api/response_builder/main.rb', line 19 def set_response prepare_response response_data = ::Api::ResponseBuilder::Data.new(resource, config).data = ::Api::ResponseBuilder::Messages.new(resource, config). status_code = ::Api::ResponseBuilder::StatusCode.new(resource, config).status_code @response[:body] = response_data if response_data.present? @response[:messages] = if .present? @response[:status_code] = status_code @response[:meta] = (config[:meta].to_h) end |