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
-
.domain(json) ⇒ Core::Domain
Converts a JSON represntation to an instance of
Core::Domain
. - .header(json) ⇒ Object private
-
.json_to_hash(json) ⇒ Hash
Converts a JSON representation to a hash.
- .load(json) ⇒ Object
- .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
-
.stage(json) ⇒ Core::Resource
Converts a JSON representation to an instance of
Core::Stage
.
Class Method Details
.api(json) ⇒ Core::API
Converts a JSON represntation to an instance of Core::API
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/useless/doc/serialization/load.rb', line 77 def self.api(json) hash = json_to_hash json resources = (hash['resources'] || []).map do |json| resource json end = begin Time.parse(hash['timestamp']) rescue TypeError, ArgumentError nil end if hash['concept'] concept = stage hash['concept'] end if hash['specification'] specification = stage hash['specification'] end if hash['implementation'] implementation = stage hash['implementation'] end Useless::Doc::Core::API.new \ name: hash['name'], url: hash['url'], timestamp: , description: hash['description'], resources: resources, concept: concept, specification: specification, implementation: implementation 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.
221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/useless/doc/serialization/load.rb', line 221 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.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/useless/doc/serialization/load.rb', line 234 def self.body_attribute(json) hash = json_to_hash json attributes = (hash['attributes'] || []).map do |json| body_attribute json end Useless::Doc::Core::Body::Attribute.new \ key: hash['key'], type: hash['type'], required: hash['required'], default: hash['default'], description: hash['description'], attributes: attributes end |
.domain(json) ⇒ Core::Domain
Converts a JSON represntation to an instance of Core::Domain
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/useless/doc/serialization/load.rb', line 48 def self.domain(json) hash = json_to_hash json apis = (hash['apis'] || []).map do |json| api json end = begin Time.parse(hash['timestamp']) rescue TypeError, ArgumentError nil end Useless::Doc::Core::Domain.new \ name: hash['name'], url: hash['url'], timestamp: , description: hash['description'], apis: apis 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.
212 213 214 215 216 217 218 |
# File 'lib/useless/doc/serialization/load.rb', line 212 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.
24 25 26 |
# File 'lib/useless/doc/serialization/load.rb', line 24 def self.json_to_hash(json) json.is_a?(Hash) ? json : Oj.load(json) end |
.load(json) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/useless/doc/serialization/load.rb', line 28 def self.load(json) hash = json_to_hash json if hash['apis'] self.domain(hash) elsif hash['url'] self.api(hash) elsif hash['path'] self.resource(hash) end 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.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/useless/doc/serialization/load.rb', line 151 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.
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/useless/doc/serialization/load.rb', line 200 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
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/useless/doc/serialization/load.rb', line 137 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.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/useless/doc/serialization/load.rb', line 181 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 |
.stage(json) ⇒ Core::Resource
Converts a JSON representation to an instance of Core::Stage
121 122 123 124 125 126 127 |
# File 'lib/useless/doc/serialization/load.rb', line 121 def self.stage(json) hash = json_to_hash json Useless::Doc::Core::Stage.new \ credit: hash['credit'], progress: hash['progress'] end |