dkron-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/DEVELOP.md +596 -0
  3. data/Gemfile +7 -0
  4. data/Gemfile.lock +69 -0
  5. data/README.md +99 -0
  6. data/Rakefile +8 -0
  7. data/dkron-ruby.gemspec +45 -0
  8. data/docs/DefaultApi.md +131 -0
  9. data/docs/Execution.md +13 -0
  10. data/docs/ExecutionsApi.md +55 -0
  11. data/docs/Job.md +28 -0
  12. data/docs/JobsApi.md +295 -0
  13. data/docs/Member.md +18 -0
  14. data/docs/MembersApi.md +49 -0
  15. data/docs/Processors.md +7 -0
  16. data/docs/Status.md +10 -0
  17. data/git_push.sh +55 -0
  18. data/lib/dkron-ruby.rb +48 -0
  19. data/lib/dkron-ruby/api/default_api.rb +161 -0
  20. data/lib/dkron-ruby/api/executions_api.rb +75 -0
  21. data/lib/dkron-ruby/api/jobs_api.rb +335 -0
  22. data/lib/dkron-ruby/api/members_api.rb +69 -0
  23. data/lib/dkron-ruby/api_client.rb +390 -0
  24. data/lib/dkron-ruby/api_error.rb +38 -0
  25. data/lib/dkron-ruby/configuration.rb +202 -0
  26. data/lib/dkron-ruby/models/execution.rb +236 -0
  27. data/lib/dkron-ruby/models/job.rb +403 -0
  28. data/lib/dkron-ruby/models/member.rb +288 -0
  29. data/lib/dkron-ruby/models/processors.rb +176 -0
  30. data/lib/dkron-ruby/models/status.rb +206 -0
  31. data/lib/dkron-ruby/version.rb +15 -0
  32. data/spec/api/default_api_spec.rb +65 -0
  33. data/spec/api/executions_api_spec.rb +46 -0
  34. data/spec/api/jobs_api_spec.rb +102 -0
  35. data/spec/api/members_api_spec.rb +45 -0
  36. data/spec/api_client_spec.rb +243 -0
  37. data/spec/configuration_spec.rb +42 -0
  38. data/spec/models/execution_spec.rb +71 -0
  39. data/spec/models/job_spec.rb +161 -0
  40. data/spec/models/member_spec.rb +101 -0
  41. data/spec/models/processors_spec.rb +35 -0
  42. data/spec/models/status_spec.rb +53 -0
  43. data/spec/spec_helper.rb +111 -0
  44. metadata +283 -0
@@ -0,0 +1,403 @@
1
+ =begin
2
+ #Dkron REST API
3
+
4
+ #You can communicate with Dkron using a RESTful JSON API over HTTP. Dkron nodes usually listen on port `8080` for API requests. All examples in this section assume that you've found a running leader at `localhost:8080`. Dkron implements a RESTful JSON API over HTTP to communicate with software clients. Dkron listens in port `8080` by default. All examples in this section assume that you're using the default port. Default API responses are unformatted JSON add the `pretty=true` param to format the response.
5
+
6
+ OpenAPI spec version: 2.2
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.13
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Dkron
16
+ # A Job represents a scheduled task to execute.
17
+ class Job
18
+ # Name for the job.
19
+ attr_accessor :name
20
+
21
+ # Nice name for the job. Optional.
22
+ attr_accessor :displayname
23
+
24
+ # Cron expression for the job.
25
+ attr_accessor :schedule
26
+
27
+ # Timezone where the job will be executed. By default and when field is set to empty string, the job will run in local time.
28
+ attr_accessor :timezone
29
+
30
+ # Owner of the job
31
+ attr_accessor :owner
32
+
33
+ # Email of the owner
34
+ attr_accessor :owner_email
35
+
36
+ # Number of successful executions
37
+ attr_accessor :success_count
38
+
39
+ # Number of failed executions
40
+ attr_accessor :error_count
41
+
42
+ # Last time this job executed successfully
43
+ attr_accessor :last_success
44
+
45
+ # Last time this job failed
46
+ attr_accessor :last_error
47
+
48
+ # Disabled state of the job
49
+ attr_accessor :disabled
50
+
51
+ # Target nodes tags of this job
52
+ attr_accessor :tags
53
+
54
+ # Extra metadata tags for this job
55
+ attr_accessor :metadata
56
+
57
+ # Number of times to retry a failed job execution
58
+ attr_accessor :retries
59
+
60
+ # The name/id of the job that will trigger the execution of this job
61
+ attr_accessor :parent_job
62
+
63
+ # Array containing the jobs that depends on this one
64
+ attr_accessor :dependent_jobs
65
+
66
+ attr_accessor :processors
67
+
68
+ # Concurrency policy for the job allow/forbid
69
+ attr_accessor :concurrency
70
+
71
+ # Executor plugin used to run the job
72
+ attr_accessor :executor
73
+
74
+ # Executor plugin parameters
75
+ attr_accessor :executor_config
76
+
77
+ # Status of the job
78
+ attr_accessor :status
79
+
80
+ # Attribute mapping from ruby-style variable name to JSON key.
81
+ def self.attribute_map
82
+ {
83
+ :'name' => :'name',
84
+ :'displayname' => :'displayname',
85
+ :'schedule' => :'schedule',
86
+ :'timezone' => :'timezone',
87
+ :'owner' => :'owner',
88
+ :'owner_email' => :'owner_email',
89
+ :'success_count' => :'success_count',
90
+ :'error_count' => :'error_count',
91
+ :'last_success' => :'last_success',
92
+ :'last_error' => :'last_error',
93
+ :'disabled' => :'disabled',
94
+ :'tags' => :'tags',
95
+ :'metadata' => :'metadata',
96
+ :'retries' => :'retries',
97
+ :'parent_job' => :'parent_job',
98
+ :'dependent_jobs' => :'dependent_jobs',
99
+ :'processors' => :'processors',
100
+ :'concurrency' => :'concurrency',
101
+ :'executor' => :'executor',
102
+ :'executor_config' => :'executor_config',
103
+ :'status' => :'status'
104
+ }
105
+ end
106
+
107
+ # Attribute type mapping.
108
+ def self.swagger_types
109
+ {
110
+ :'name' => :'String',
111
+ :'displayname' => :'String',
112
+ :'schedule' => :'String',
113
+ :'timezone' => :'String',
114
+ :'owner' => :'String',
115
+ :'owner_email' => :'String',
116
+ :'success_count' => :'Integer',
117
+ :'error_count' => :'Integer',
118
+ :'last_success' => :'DateTime',
119
+ :'last_error' => :'DateTime',
120
+ :'disabled' => :'BOOLEAN',
121
+ :'tags' => :'Hash<String, String>',
122
+ :'metadata' => :'Hash<String, String>',
123
+ :'retries' => :'Integer',
124
+ :'parent_job' => :'String',
125
+ :'dependent_jobs' => :'Array<String>',
126
+ :'processors' => :'Processors',
127
+ :'concurrency' => :'String',
128
+ :'executor' => :'String',
129
+ :'executor_config' => :'Hash<String, String>',
130
+ :'status' => :'String'
131
+ }
132
+ end
133
+
134
+ # Initializes the object
135
+ # @param [Hash] attributes Model attributes in the form of hash
136
+ def initialize(attributes = {})
137
+ return unless attributes.is_a?(Hash)
138
+
139
+ # convert string to symbol for hash key
140
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
141
+
142
+ if attributes.has_key?(:'name')
143
+ self.name = attributes[:'name']
144
+ end
145
+
146
+ if attributes.has_key?(:'displayname')
147
+ self.displayname = attributes[:'displayname']
148
+ end
149
+
150
+ if attributes.has_key?(:'schedule')
151
+ self.schedule = attributes[:'schedule']
152
+ end
153
+
154
+ if attributes.has_key?(:'timezone')
155
+ self.timezone = attributes[:'timezone']
156
+ end
157
+
158
+ if attributes.has_key?(:'owner')
159
+ self.owner = attributes[:'owner']
160
+ end
161
+
162
+ if attributes.has_key?(:'owner_email')
163
+ self.owner_email = attributes[:'owner_email']
164
+ end
165
+
166
+ if attributes.has_key?(:'success_count')
167
+ self.success_count = attributes[:'success_count']
168
+ end
169
+
170
+ if attributes.has_key?(:'error_count')
171
+ self.error_count = attributes[:'error_count']
172
+ end
173
+
174
+ if attributes.has_key?(:'last_success')
175
+ self.last_success = attributes[:'last_success']
176
+ end
177
+
178
+ if attributes.has_key?(:'last_error')
179
+ self.last_error = attributes[:'last_error']
180
+ end
181
+
182
+ if attributes.has_key?(:'disabled')
183
+ self.disabled = attributes[:'disabled']
184
+ end
185
+
186
+ if attributes.has_key?(:'tags')
187
+ if (value = attributes[:'tags']).is_a?(Hash)
188
+ self.tags = value
189
+ end
190
+ end
191
+
192
+ if attributes.has_key?(:'metadata')
193
+ if (value = attributes[:'metadata']).is_a?(Hash)
194
+ self.metadata = value
195
+ end
196
+ end
197
+
198
+ if attributes.has_key?(:'retries')
199
+ self.retries = attributes[:'retries']
200
+ end
201
+
202
+ if attributes.has_key?(:'parent_job')
203
+ self.parent_job = attributes[:'parent_job']
204
+ end
205
+
206
+ if attributes.has_key?(:'dependent_jobs')
207
+ if (value = attributes[:'dependent_jobs']).is_a?(Array)
208
+ self.dependent_jobs = value
209
+ end
210
+ end
211
+
212
+ if attributes.has_key?(:'processors')
213
+ self.processors = attributes[:'processors']
214
+ end
215
+
216
+ if attributes.has_key?(:'concurrency')
217
+ self.concurrency = attributes[:'concurrency']
218
+ end
219
+
220
+ if attributes.has_key?(:'executor')
221
+ self.executor = attributes[:'executor']
222
+ end
223
+
224
+ if attributes.has_key?(:'executor_config')
225
+ if (value = attributes[:'executor_config']).is_a?(Hash)
226
+ self.executor_config = value
227
+ end
228
+ end
229
+
230
+ if attributes.has_key?(:'status')
231
+ self.status = attributes[:'status']
232
+ end
233
+ end
234
+
235
+ # Show invalid properties with the reasons. Usually used together with valid?
236
+ # @return Array for valid properties with the reasons
237
+ def list_invalid_properties
238
+ invalid_properties = Array.new
239
+ if @name.nil?
240
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
241
+ end
242
+
243
+ if @schedule.nil?
244
+ invalid_properties.push('invalid value for "schedule", schedule cannot be nil.')
245
+ end
246
+
247
+ invalid_properties
248
+ end
249
+
250
+ # Check to see if the all the properties in the model are valid
251
+ # @return true if the model is valid
252
+ def valid?
253
+ return false if @name.nil?
254
+ return false if @schedule.nil?
255
+ true
256
+ end
257
+
258
+ # Checks equality by comparing each attribute.
259
+ # @param [Object] Object to be compared
260
+ def ==(o)
261
+ return true if self.equal?(o)
262
+ self.class == o.class &&
263
+ name == o.name &&
264
+ displayname == o.displayname &&
265
+ schedule == o.schedule &&
266
+ timezone == o.timezone &&
267
+ owner == o.owner &&
268
+ owner_email == o.owner_email &&
269
+ success_count == o.success_count &&
270
+ error_count == o.error_count &&
271
+ last_success == o.last_success &&
272
+ last_error == o.last_error &&
273
+ disabled == o.disabled &&
274
+ tags == o.tags &&
275
+ metadata == o.metadata &&
276
+ retries == o.retries &&
277
+ parent_job == o.parent_job &&
278
+ dependent_jobs == o.dependent_jobs &&
279
+ processors == o.processors &&
280
+ concurrency == o.concurrency &&
281
+ executor == o.executor &&
282
+ executor_config == o.executor_config &&
283
+ status == o.status
284
+ end
285
+
286
+ # @see the `==` method
287
+ # @param [Object] Object to be compared
288
+ def eql?(o)
289
+ self == o
290
+ end
291
+
292
+ # Calculates hash code according to all attributes.
293
+ # @return [Fixnum] Hash code
294
+ def hash
295
+ [name, displayname, schedule, timezone, owner, owner_email, success_count, error_count, last_success, last_error, disabled, tags, metadata, retries, parent_job, dependent_jobs, processors, concurrency, executor, executor_config, status].hash
296
+ end
297
+
298
+ # Builds the object from hash
299
+ # @param [Hash] attributes Model attributes in the form of hash
300
+ # @return [Object] Returns the model itself
301
+ def build_from_hash(attributes)
302
+ return nil unless attributes.is_a?(Hash)
303
+ self.class.swagger_types.each_pair do |key, type|
304
+ if type =~ /\AArray<(.*)>/i
305
+ # check to ensure the input is an array given that the attribute
306
+ # is documented as an array but the input is not
307
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
308
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
309
+ end
310
+ elsif !attributes[self.class.attribute_map[key]].nil?
311
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
312
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
313
+ end
314
+
315
+ self
316
+ end
317
+
318
+ # Deserializes the data based on type
319
+ # @param string type Data type
320
+ # @param string value Value to be deserialized
321
+ # @return [Object] Deserialized data
322
+ def _deserialize(type, value)
323
+ case type.to_sym
324
+ when :DateTime
325
+ DateTime.parse(value)
326
+ when :Date
327
+ Date.parse(value)
328
+ when :String
329
+ value.to_s
330
+ when :Integer
331
+ value.to_i
332
+ when :Float
333
+ value.to_f
334
+ when :BOOLEAN
335
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
336
+ true
337
+ else
338
+ false
339
+ end
340
+ when :Object
341
+ # generic object (usually a Hash), return directly
342
+ value
343
+ when /\AArray<(?<inner_type>.+)>\z/
344
+ inner_type = Regexp.last_match[:inner_type]
345
+ value.map { |v| _deserialize(inner_type, v) }
346
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
347
+ k_type = Regexp.last_match[:k_type]
348
+ v_type = Regexp.last_match[:v_type]
349
+ {}.tap do |hash|
350
+ value.each do |k, v|
351
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
352
+ end
353
+ end
354
+ else # model
355
+ temp_model = Dkron.const_get(type).new
356
+ temp_model.build_from_hash(value)
357
+ end
358
+ end
359
+
360
+ # Returns the string representation of the object
361
+ # @return [String] String presentation of the object
362
+ def to_s
363
+ to_hash.to_s
364
+ end
365
+
366
+ # to_body is an alias to to_hash (backward compatibility)
367
+ # @return [Hash] Returns the object in the form of hash
368
+ def to_body
369
+ to_hash
370
+ end
371
+
372
+ # Returns the object in the form of hash
373
+ # @return [Hash] Returns the object in the form of hash
374
+ def to_hash
375
+ hash = {}
376
+ self.class.attribute_map.each_pair do |attr, param|
377
+ value = self.send(attr)
378
+ next if value.nil?
379
+ hash[param] = _to_hash(value)
380
+ end
381
+ hash
382
+ end
383
+
384
+ # Outputs non-array value in the form of hash
385
+ # For object, use to_hash. Otherwise, just return the value
386
+ # @param [Object] value Any valid value
387
+ # @return [Hash] Returns the value in the form of hash
388
+ def _to_hash(value)
389
+ if value.is_a?(Array)
390
+ value.compact.map { |v| _to_hash(v) }
391
+ elsif value.is_a?(Hash)
392
+ {}.tap do |hash|
393
+ value.each { |k, v| hash[k] = _to_hash(v) }
394
+ end
395
+ elsif value.respond_to? :to_hash
396
+ value.to_hash
397
+ else
398
+ value
399
+ end
400
+ end
401
+
402
+ end
403
+ end
@@ -0,0 +1,288 @@
1
+ =begin
2
+ #Dkron REST API
3
+
4
+ #You can communicate with Dkron using a RESTful JSON API over HTTP. Dkron nodes usually listen on port `8080` for API requests. All examples in this section assume that you've found a running leader at `localhost:8080`. Dkron implements a RESTful JSON API over HTTP to communicate with software clients. Dkron listens in port `8080` by default. All examples in this section assume that you're using the default port. Default API responses are unformatted JSON add the `pretty=true` param to format the response.
5
+
6
+ OpenAPI spec version: 2.2
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.13
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Dkron
16
+ # A member represents a cluster member node.
17
+ class Member
18
+ # Node name
19
+ attr_accessor :name
20
+
21
+ # IP Address
22
+ attr_accessor :addr
23
+
24
+ # Port number
25
+ attr_accessor :port
26
+
27
+ # Tags asociated with this node
28
+ attr_accessor :tags
29
+
30
+ # The serf status of the node see: https://godoc.org/github.com/hashicorp/serf/serf#MemberStatus
31
+ attr_accessor :status
32
+
33
+ # Serf protocol minimum version this node can understand or speak
34
+ attr_accessor :protocol_min
35
+
36
+ # Serf protocol maximum version this node can understand or speak
37
+ attr_accessor :protocol_max
38
+
39
+ # Serf protocol current version this node can understand or speak
40
+ attr_accessor :protocol_cur
41
+
42
+ # Serf delegate protocol minimum version this node can understand or speak
43
+ attr_accessor :delegate_min
44
+
45
+ # Serf delegate protocol maximum version this node can understand or speak
46
+ attr_accessor :delegate_max
47
+
48
+ # Serf delegate protocol current version this node can understand or speak
49
+ attr_accessor :delegate_cur
50
+
51
+ # Attribute mapping from ruby-style variable name to JSON key.
52
+ def self.attribute_map
53
+ {
54
+ :'name' => :'Name',
55
+ :'addr' => :'Addr',
56
+ :'port' => :'Port',
57
+ :'tags' => :'Tags',
58
+ :'status' => :'Status',
59
+ :'protocol_min' => :'ProtocolMin',
60
+ :'protocol_max' => :'ProtocolMax',
61
+ :'protocol_cur' => :'ProtocolCur',
62
+ :'delegate_min' => :'DelegateMin',
63
+ :'delegate_max' => :'DelegateMax',
64
+ :'delegate_cur' => :'DelegateCur'
65
+ }
66
+ end
67
+
68
+ # Attribute type mapping.
69
+ def self.swagger_types
70
+ {
71
+ :'name' => :'String',
72
+ :'addr' => :'String',
73
+ :'port' => :'Integer',
74
+ :'tags' => :'Hash<String, String>',
75
+ :'status' => :'Integer',
76
+ :'protocol_min' => :'Integer',
77
+ :'protocol_max' => :'Integer',
78
+ :'protocol_cur' => :'Integer',
79
+ :'delegate_min' => :'Integer',
80
+ :'delegate_max' => :'Integer',
81
+ :'delegate_cur' => :'Integer'
82
+ }
83
+ end
84
+
85
+ # Initializes the object
86
+ # @param [Hash] attributes Model attributes in the form of hash
87
+ def initialize(attributes = {})
88
+ return unless attributes.is_a?(Hash)
89
+
90
+ # convert string to symbol for hash key
91
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
92
+
93
+ if attributes.has_key?(:'Name')
94
+ self.name = attributes[:'Name']
95
+ end
96
+
97
+ if attributes.has_key?(:'Addr')
98
+ self.addr = attributes[:'Addr']
99
+ end
100
+
101
+ if attributes.has_key?(:'Port')
102
+ self.port = attributes[:'Port']
103
+ end
104
+
105
+ if attributes.has_key?(:'Tags')
106
+ if (value = attributes[:'Tags']).is_a?(Hash)
107
+ self.tags = value
108
+ end
109
+ end
110
+
111
+ if attributes.has_key?(:'Status')
112
+ self.status = attributes[:'Status']
113
+ end
114
+
115
+ if attributes.has_key?(:'ProtocolMin')
116
+ self.protocol_min = attributes[:'ProtocolMin']
117
+ end
118
+
119
+ if attributes.has_key?(:'ProtocolMax')
120
+ self.protocol_max = attributes[:'ProtocolMax']
121
+ end
122
+
123
+ if attributes.has_key?(:'ProtocolCur')
124
+ self.protocol_cur = attributes[:'ProtocolCur']
125
+ end
126
+
127
+ if attributes.has_key?(:'DelegateMin')
128
+ self.delegate_min = attributes[:'DelegateMin']
129
+ end
130
+
131
+ if attributes.has_key?(:'DelegateMax')
132
+ self.delegate_max = attributes[:'DelegateMax']
133
+ end
134
+
135
+ if attributes.has_key?(:'DelegateCur')
136
+ self.delegate_cur = attributes[:'DelegateCur']
137
+ end
138
+ end
139
+
140
+ # Show invalid properties with the reasons. Usually used together with valid?
141
+ # @return Array for valid properties with the reasons
142
+ def list_invalid_properties
143
+ invalid_properties = Array.new
144
+ invalid_properties
145
+ end
146
+
147
+ # Check to see if the all the properties in the model are valid
148
+ # @return true if the model is valid
149
+ def valid?
150
+ true
151
+ end
152
+
153
+ # Checks equality by comparing each attribute.
154
+ # @param [Object] Object to be compared
155
+ def ==(o)
156
+ return true if self.equal?(o)
157
+ self.class == o.class &&
158
+ name == o.name &&
159
+ addr == o.addr &&
160
+ port == o.port &&
161
+ tags == o.tags &&
162
+ status == o.status &&
163
+ protocol_min == o.protocol_min &&
164
+ protocol_max == o.protocol_max &&
165
+ protocol_cur == o.protocol_cur &&
166
+ delegate_min == o.delegate_min &&
167
+ delegate_max == o.delegate_max &&
168
+ delegate_cur == o.delegate_cur
169
+ end
170
+
171
+ # @see the `==` method
172
+ # @param [Object] Object to be compared
173
+ def eql?(o)
174
+ self == o
175
+ end
176
+
177
+ # Calculates hash code according to all attributes.
178
+ # @return [Fixnum] Hash code
179
+ def hash
180
+ [name, addr, port, tags, status, protocol_min, protocol_max, protocol_cur, delegate_min, delegate_max, delegate_cur].hash
181
+ end
182
+
183
+ # Builds the object from hash
184
+ # @param [Hash] attributes Model attributes in the form of hash
185
+ # @return [Object] Returns the model itself
186
+ def build_from_hash(attributes)
187
+ return nil unless attributes.is_a?(Hash)
188
+ self.class.swagger_types.each_pair do |key, type|
189
+ if type =~ /\AArray<(.*)>/i
190
+ # check to ensure the input is an array given that the attribute
191
+ # is documented as an array but the input is not
192
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
193
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
194
+ end
195
+ elsif !attributes[self.class.attribute_map[key]].nil?
196
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
197
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
198
+ end
199
+
200
+ self
201
+ end
202
+
203
+ # Deserializes the data based on type
204
+ # @param string type Data type
205
+ # @param string value Value to be deserialized
206
+ # @return [Object] Deserialized data
207
+ def _deserialize(type, value)
208
+ case type.to_sym
209
+ when :DateTime
210
+ DateTime.parse(value)
211
+ when :Date
212
+ Date.parse(value)
213
+ when :String
214
+ value.to_s
215
+ when :Integer
216
+ value.to_i
217
+ when :Float
218
+ value.to_f
219
+ when :BOOLEAN
220
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
221
+ true
222
+ else
223
+ false
224
+ end
225
+ when :Object
226
+ # generic object (usually a Hash), return directly
227
+ value
228
+ when /\AArray<(?<inner_type>.+)>\z/
229
+ inner_type = Regexp.last_match[:inner_type]
230
+ value.map { |v| _deserialize(inner_type, v) }
231
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
232
+ k_type = Regexp.last_match[:k_type]
233
+ v_type = Regexp.last_match[:v_type]
234
+ {}.tap do |hash|
235
+ value.each do |k, v|
236
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
237
+ end
238
+ end
239
+ else # model
240
+ temp_model = Dkron.const_get(type).new
241
+ temp_model.build_from_hash(value)
242
+ end
243
+ end
244
+
245
+ # Returns the string representation of the object
246
+ # @return [String] String presentation of the object
247
+ def to_s
248
+ to_hash.to_s
249
+ end
250
+
251
+ # to_body is an alias to to_hash (backward compatibility)
252
+ # @return [Hash] Returns the object in the form of hash
253
+ def to_body
254
+ to_hash
255
+ end
256
+
257
+ # Returns the object in the form of hash
258
+ # @return [Hash] Returns the object in the form of hash
259
+ def to_hash
260
+ hash = {}
261
+ self.class.attribute_map.each_pair do |attr, param|
262
+ value = self.send(attr)
263
+ next if value.nil?
264
+ hash[param] = _to_hash(value)
265
+ end
266
+ hash
267
+ end
268
+
269
+ # Outputs non-array value in the form of hash
270
+ # For object, use to_hash. Otherwise, just return the value
271
+ # @param [Object] value Any valid value
272
+ # @return [Hash] Returns the value in the form of hash
273
+ def _to_hash(value)
274
+ if value.is_a?(Array)
275
+ value.compact.map { |v| _to_hash(v) }
276
+ elsif value.is_a?(Hash)
277
+ {}.tap do |hash|
278
+ value.each { |k, v| hash[k] = _to_hash(v) }
279
+ end
280
+ elsif value.respond_to? :to_hash
281
+ value.to_hash
282
+ else
283
+ value
284
+ end
285
+ end
286
+
287
+ end
288
+ end