Module: Useless::Doc::Serialization::Dump
- Defined in:
- lib/useless/doc/serialization/dump.rb
Class Method Summary collapse
- .action(action) ⇒ Object private
- .body(body) ⇒ Object private
- .body_attribute(attribute) ⇒ Object private
-
.hash_to_json(hash) ⇒ String
Converts a hash to a JSON representation.
- .header(header) ⇒ Object private
- .request(request) ⇒ Object private
- .request_parameter(parameter) ⇒ Object private
-
.resource(resource) ⇒ String
Converts
Doc::Resource
instance to a JSON representation. - .response(response) ⇒ Object private
- .response_status(status) ⇒ Object private
Class Method Details
.action(action) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/useless/doc/serialization/dump.rb', line 37 def self.action(action) if action hash_to_json \ 'description' => action.description, 'method' => action.method, 'authentication_required' => action.authentication_required, 'request' => request(action.request), 'response' => response(action.response) end end |
.body(body) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 102 103 104 105 |
# File 'lib/useless/doc/serialization/dump.rb', line 99 def self.body(body) if body hash_to_json \ 'content_type' => body.content_type, 'attributes' => body.attributes.map { |attribute| body_attribute(attribute) } end end |
.body_attribute(attribute) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/useless/doc/serialization/dump.rb', line 108 def self.body_attribute(attribute) if attribute hash_to_json \ 'key' => attribute.key, 'type' => attribute.type, 'required' => attribute.required, 'default' => attribute.default, 'description' => attribute.description end end |
.hash_to_json(hash) ⇒ String
Converts a hash to a JSON representation.
17 18 19 |
# File 'lib/useless/doc/serialization/dump.rb', line 17 def self.hash_to_json(hash) hash.is_a?(String) ? hash : Oj.dump(hash) end |
.header(header) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 84 85 86 87 |
# File 'lib/useless/doc/serialization/dump.rb', line 81 def self.header(header) if header hash_to_json \ 'key' => header.key, 'description' => header.description end end |
.request(request) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 52 53 54 55 56 |
# File 'lib/useless/doc/serialization/dump.rb', line 49 def self.request(request) if request hash_to_json \ 'parameters' => request.parameters.map { |parameter| request_parameter(parameter) }, 'headers' => request.headers.map { |header| header(header) }, 'body' => body(request.body) end end |
.request_parameter(parameter) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/useless/doc/serialization/dump.rb', line 69 def self.request_parameter(parameter) if parameter hash_to_json \ 'type' => parameter.type, 'key' => parameter.key, 'required' => parameter.required, 'default' => parameter.default, 'description' => parameter.description end end |
.resource(resource) ⇒ String
Converts Doc::Resource
instance to a JSON representation.
27 28 29 30 31 32 33 34 |
# File 'lib/useless/doc/serialization/dump.rb', line 27 def self.resource(resource) if resource hash_to_json \ 'path' => resource.path, 'description' => resource.description, 'actions' => resource.actions.map { |action| action(action) } end end |
.response(response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 62 63 64 65 66 |
# File 'lib/useless/doc/serialization/dump.rb', line 59 def self.response(response) if response hash_to_json \ 'statuses' => response.statuses.map { |status| response_status(status) }, 'headers' => response.headers.map { |header| header(header) }, 'body' => body(response.body) end end |
.response_status(status) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 94 95 96 |
# File 'lib/useless/doc/serialization/dump.rb', line 90 def self.response_status(status) if status hash_to_json \ 'code' => status.code, 'description' => status.description end end |