Module: Useless::Doc::Serialization::Dump

Defined in:
lib/useless/doc/serialization/dump.rb

Class Method Summary collapse

Class Method Details

.api(api) ⇒ String

Converts Core::API instance to a JSON representation.

Parameters:

  • the API to be converted to JSON.

Returns:

  • a JSON representation of the specified API.



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/useless/doc/serialization/dump.rb', line 44

def self.api(api)
  if api
    hash_to_json \
      'name' => api.name,
      'url' => api.url,
      'description' => api.description,
      'timestamp' => api.timestamp ? api.timestamp.iso8601 : nil,
      'resources' => api.resources.map { |resource| resource(resource) },
      'concept' => stage(api.concept),
      'specification' => stage(api.specification),
      'implementation' => stage(api.implementation)
  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.

API:

  • private



143
144
145
146
147
148
149
# File 'lib/useless/doc/serialization/dump.rb', line 143

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.

API:

  • private



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/useless/doc/serialization/dump.rb', line 152

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,
      'attributes' => attribute.attributes.map { |attribute| body_attribute(attribute) }
  end
end

.domain(domain) ⇒ String

Converts Core::Domain instance to a JSON representation.

Parameters:

  • the domain to be converted to JSON.

Returns:

  • a JSON representation of the specified domain.



27
28
29
30
31
32
33
34
35
36
# File 'lib/useless/doc/serialization/dump.rb', line 27

def self.domain(domain)
  if domain
    hash_to_json \
      'name' => domain.name,
      'url' => domain.url,
      'description' => domain.description,
      'timestamp' => domain.timestamp ? domain.timestamp.iso8601 : nil,
      'apis' => domain.apis.map { |api| api(api) }
  end
end

.hash_to_json(hash) ⇒ String

Converts a hash to a JSON representation.

Parameters:

  • the hash to be converted.

Returns:

  • a JSON representation corresponding to the specified hash.

Raises:

  • if json is not a Hash, String or IO.



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.

API:

  • private



125
126
127
128
129
130
131
# File 'lib/useless/doc/serialization/dump.rb', line 125

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.

API:

  • private



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/useless/doc/serialization/dump.rb', line 88

def self.request(request)
  if request
    hash_to_json \
      'method' => request.method,
      'description' => request.description,
      'authentication_required' => request.authentication_required,
      'parameters' => request.parameters.map { |parameter| request_parameter(parameter) },
      'headers' => request.headers.map { |header| header(header) },
      'body' => body(request.body),
      'responses' => request.responses.map { |response| response(response) }
  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.

API:

  • private



113
114
115
116
117
118
119
120
121
122
# File 'lib/useless/doc/serialization/dump.rb', line 113

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 a Core::Resource instance to a JSON representation.

Parameters:

  • the resource to be converted to JSON.

Returns:

  • a JSON representation of the specified resource.



78
79
80
81
82
83
84
85
# File 'lib/useless/doc/serialization/dump.rb', line 78

def self.resource(resource)
  if resource
    hash_to_json \
      'path' => resource.path,
      'description' => resource.description,
      'requests' => resource.requests.map { |request| request(request) }
  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.

API:

  • private



102
103
104
105
106
107
108
109
110
# File 'lib/useless/doc/serialization/dump.rb', line 102

def self.response(response)
  if response
    hash_to_json \
      'code' => response.code,
      'description' => response.description,
      '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.

API:

  • private



134
135
136
137
138
139
140
# File 'lib/useless/doc/serialization/dump.rb', line 134

def self.response_status(status)
  if status
    hash_to_json \
      'code' => status.code,
      'description' => status.description
  end
end

.stage(stage) ⇒ String

Converts Core::Stage instance to a JSON representation.

Parameters:

  • the stage to be converted to JSON.

Returns:

  • a JSON representation of the specified stage.



64
65
66
67
68
69
70
# File 'lib/useless/doc/serialization/dump.rb', line 64

def self.stage(stage)
  if stage
    hash_to_json \
      'credit' => stage.credit,
      'progress' => stage.progress
  end
end