Module: Useless::Doc::Serialization::Load
- Defined in:
- lib/useless/doc/serialization/load.rb
Class Method Summary collapse
-
.api(json) ⇒ Core::API
Converts a JSON represntation to an instance of
Core::API. - .body(json) ⇒ Object private
- .body_attribute(json) ⇒ Object private
- .header(json) ⇒ Object private
-
.json_to_hash(json) ⇒ Hash
Converts a JSON representation to a hash.
- .request(json) ⇒ Object private
- .request_parameter(json) ⇒ Object private
-
.resource(json) ⇒ Core::Resource
Converts a JSON represntation to an instance of
Core::Resource. - .response(json) ⇒ Object private
Class Method Details
.api(json) ⇒ Core::API
Converts a JSON represntation to an instance of Core::API
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/useless/doc/serialization/load.rb', line 35 def self.api(json) hash = json_to_hash json resources = (hash['resources'] || []).map do |json| resource json end Useless::Doc::Core::API.new \ url: hash['url'], description: hash['description'], resources: resources end |
.body(json) ⇒ 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.
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/useless/doc/serialization/load.rb', line 140 def self.body(json) hash = json_to_hash json attributes = (hash['attributes'] || []).map do |json| body_attribute json end Useless::Doc::Core::Body.new \ content_type: hash['content_type'], attributes: attributes end |
.body_attribute(json) ⇒ 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.
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/useless/doc/serialization/load.rb', line 153 def self.body_attribute(json) hash = json_to_hash json Useless::Doc::Core::Body::Attribute.new \ key: hash['key'], type: hash['type'], required: hash['required'], default: hash['default'], description: hash['description'] end |
.header(json) ⇒ 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.
131 132 133 134 135 136 137 |
# File 'lib/useless/doc/serialization/load.rb', line 131 def self.header(json) hash = json_to_hash json Useless::Doc::Core::Header.new \ key: hash['key'], description: hash['description'] end |
.json_to_hash(json) ⇒ Hash
Converts a JSON representation to a hash.
23 24 25 |
# File 'lib/useless/doc/serialization/load.rb', line 23 def self.json_to_hash(json) json.is_a?(Hash) ? json : Oj.load(json) end |
.request(json) ⇒ 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/useless/doc/serialization/load.rb', line 70 def self.request(json) hash = json_to_hash json parameters = (hash['parameters'] || []).map do |json| request_parameter json end headers = (hash['headers'] || []).map do |json| header json end if hash['body'] body = body hash['body'] end responses = (hash['responses'] || []).map do |json| response json end Useless::Doc::Core::Request.new \ method: hash['method'], description: hash['description'], authentication_required: hash['authentication_required'], parameters: parameters, headers: headers, body: body, responses: responses end |
.request_parameter(json) ⇒ 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.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/useless/doc/serialization/load.rb', line 119 def self.request_parameter(json) hash = json_to_hash json Useless::Doc::Core::Request::Parameter.new \ type: hash['type'], key: hash['key'], required: hash['required'], default: hash['default'], description: hash['description'] end |
.resource(json) ⇒ Core::Resource
Converts a JSON represntation to an instance of Core::Resource
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/useless/doc/serialization/load.rb', line 56 def self.resource(json) hash = json_to_hash json requests = (hash['requests'] || []).map do |json| request json end Useless::Doc::Core::Resource.new \ path: hash['path'], description: hash['description'], requests: requests end |
.response(json) ⇒ 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.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/useless/doc/serialization/load.rb', line 100 def self.response(json) hash = json_to_hash json headers = (hash['headers'] || []).map do |json| header json end if hash['body'] body = body hash['body'] end Useless::Doc::Core::Response.new \ code: hash['code'], description: hash['description'], headers: headers, body: body end |