rbflagr 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/Makefile +9 -0
  4. data/README.md +143 -0
  5. data/Rakefile +8 -0
  6. data/docs/Constraint.md +11 -0
  7. data/docs/ConstraintApi.md +211 -0
  8. data/docs/CreateConstraintRequest.md +10 -0
  9. data/docs/CreateFlagRequest.md +8 -0
  10. data/docs/CreateSegmentRequest.md +9 -0
  11. data/docs/CreateVariantRequest.md +9 -0
  12. data/docs/Distribution.md +12 -0
  13. data/docs/DistributionApi.md +109 -0
  14. data/docs/Error.md +8 -0
  15. data/docs/EvalContext.md +12 -0
  16. data/docs/EvalDebugLog.md +9 -0
  17. data/docs/EvalResult.md +16 -0
  18. data/docs/EvaluationApi.md +98 -0
  19. data/docs/EvaluationBatchRequest.md +10 -0
  20. data/docs/EvaluationBatchResponse.md +8 -0
  21. data/docs/EvaluationEntity.md +10 -0
  22. data/docs/Flag.md +13 -0
  23. data/docs/FlagApi.md +337 -0
  24. data/docs/FlagSnapshot.md +11 -0
  25. data/docs/HealthApi.md +46 -0
  26. data/docs/PutDistributionsRequest.md +8 -0
  27. data/docs/PutFlagRequest.md +9 -0
  28. data/docs/PutSegmentReorderRequest.md +8 -0
  29. data/docs/PutSegmentRequest.md +9 -0
  30. data/docs/PutVariantRequest.md +9 -0
  31. data/docs/Segment.md +13 -0
  32. data/docs/SegmentApi.md +246 -0
  33. data/docs/SegmentDebugLog.md +9 -0
  34. data/docs/SetFlagEnabledRequest.md +8 -0
  35. data/docs/Variant.md +10 -0
  36. data/docs/VariantApi.md +199 -0
  37. data/git_push.sh +55 -0
  38. data/lib/rbflagr.rb +70 -0
  39. data/lib/rbflagr/api/constraint_api.rb +310 -0
  40. data/lib/rbflagr/api/distribution_api.rb +159 -0
  41. data/lib/rbflagr/api/evaluation_api.rb +123 -0
  42. data/lib/rbflagr/api/flag_api.rb +413 -0
  43. data/lib/rbflagr/api/health_api.rb +66 -0
  44. data/lib/rbflagr/api/segment_api.rb +329 -0
  45. data/lib/rbflagr/api/variant_api.rb +270 -0
  46. data/lib/rbflagr/api_client.rb +388 -0
  47. data/lib/rbflagr/api_error.rb +38 -0
  48. data/lib/rbflagr/configuration.rb +202 -0
  49. data/lib/rbflagr/models/constraint.rb +317 -0
  50. data/lib/rbflagr/models/create_constraint_request.rb +273 -0
  51. data/lib/rbflagr/models/create_flag_request.rb +207 -0
  52. data/lib/rbflagr/models/create_segment_request.rb +249 -0
  53. data/lib/rbflagr/models/create_variant_request.rb +216 -0
  54. data/lib/rbflagr/models/distribution.rb +330 -0
  55. data/lib/rbflagr/models/error.rb +207 -0
  56. data/lib/rbflagr/models/eval_context.rb +268 -0
  57. data/lib/rbflagr/models/eval_debug_log.rb +194 -0
  58. data/lib/rbflagr/models/eval_result.rb +385 -0
  59. data/lib/rbflagr/models/evaluation_batch_request.rb +215 -0
  60. data/lib/rbflagr/models/evaluation_batch_response.rb +190 -0
  61. data/lib/rbflagr/models/evaluation_entity.rb +225 -0
  62. data/lib/rbflagr/models/flag.rb +282 -0
  63. data/lib/rbflagr/models/flag_snapshot.rb +263 -0
  64. data/lib/rbflagr/models/put_distributions_request.rb +190 -0
  65. data/lib/rbflagr/models/put_flag_request.rb +217 -0
  66. data/lib/rbflagr/models/put_segment_reorder_request.rb +190 -0
  67. data/lib/rbflagr/models/put_segment_request.rb +249 -0
  68. data/lib/rbflagr/models/put_variant_request.rb +221 -0
  69. data/lib/rbflagr/models/segment.rb +328 -0
  70. data/lib/rbflagr/models/segment_debug_log.rb +207 -0
  71. data/lib/rbflagr/models/set_flag_enabled_request.rb +188 -0
  72. data/lib/rbflagr/models/variant.rb +240 -0
  73. data/lib/rbflagr/version.rb +15 -0
  74. data/rbflagr.gemspec +45 -0
  75. data/spec/api/constraint_api_spec.rb +91 -0
  76. data/spec/api/distribution_api_spec.rb +62 -0
  77. data/spec/api/evaluation_api_spec.rb +47 -0
  78. data/spec/api/flag_api_spec.rb +108 -0
  79. data/spec/api/health_api_spec.rb +44 -0
  80. data/spec/api/segment_api_spec.rb +87 -0
  81. data/spec/api/variant_api_spec.rb +87 -0
  82. data/spec/api_client_spec.rb +226 -0
  83. data/spec/configuration_spec.rb +42 -0
  84. data/spec/models/constraint_spec.rb +64 -0
  85. data/spec/models/create_constraint_request_spec.rb +54 -0
  86. data/spec/models/create_flag_request_spec.rb +42 -0
  87. data/spec/models/create_segment_request_spec.rb +48 -0
  88. data/spec/models/create_variant_request_spec.rb +48 -0
  89. data/spec/models/distribution_spec.rb +66 -0
  90. data/spec/models/error_spec.rb +42 -0
  91. data/spec/models/eval_context_spec.rb +66 -0
  92. data/spec/models/eval_debug_log_spec.rb +48 -0
  93. data/spec/models/eval_result_spec.rb +78 -0
  94. data/spec/models/evaluation_batch_request_spec.rb +54 -0
  95. data/spec/models/evaluation_batch_response_spec.rb +42 -0
  96. data/spec/models/evaluation_entity_spec.rb +54 -0
  97. data/spec/models/flag_snapshot_spec.rb +60 -0
  98. data/spec/models/flag_spec.rb +66 -0
  99. data/spec/models/put_distributions_request_spec.rb +42 -0
  100. data/spec/models/put_flag_request_spec.rb +42 -0
  101. data/spec/models/put_segment_reorder_request_spec.rb +42 -0
  102. data/spec/models/put_segment_request_spec.rb +48 -0
  103. data/spec/models/put_variant_request_spec.rb +48 -0
  104. data/spec/models/segment_debug_log_spec.rb +48 -0
  105. data/spec/models/segment_spec.rb +72 -0
  106. data/spec/models/set_flag_enabled_request_spec.rb +42 -0
  107. data/spec/models/variant_spec.rb +54 -0
  108. data/spec/spec_helper.rb +111 -0
  109. data/swagger.yaml +1135 -0
  110. data/swagger_ruby.json +6 -0
  111. data/tags +618 -0
  112. metadata +362 -0
@@ -0,0 +1,282 @@
1
+ =begin
2
+ #Flagr
3
+
4
+ #Flagr is a feature flagging, A/B testing and dynamic configuration microservice
5
+
6
+ OpenAPI spec version: 1.0.8
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Flagr
16
+ class Flag
17
+ attr_accessor :id
18
+
19
+ attr_accessor :description
20
+
21
+ attr_accessor :enabled
22
+
23
+ attr_accessor :segments
24
+
25
+ attr_accessor :variants
26
+
27
+ # enabled data records will get data logging in the metrics pipeline, for example, kafka.
28
+ attr_accessor :data_records_enabled
29
+
30
+ # Attribute mapping from ruby-style variable name to JSON key.
31
+ def self.attribute_map
32
+ {
33
+ :'id' => :'id',
34
+ :'description' => :'description',
35
+ :'enabled' => :'enabled',
36
+ :'segments' => :'segments',
37
+ :'variants' => :'variants',
38
+ :'data_records_enabled' => :'dataRecordsEnabled'
39
+ }
40
+ end
41
+
42
+ # Attribute type mapping.
43
+ def self.swagger_types
44
+ {
45
+ :'id' => :'Integer',
46
+ :'description' => :'String',
47
+ :'enabled' => :'BOOLEAN',
48
+ :'segments' => :'Array<Segment>',
49
+ :'variants' => :'Array<Variant>',
50
+ :'data_records_enabled' => :'BOOLEAN'
51
+ }
52
+ end
53
+
54
+ # Initializes the object
55
+ # @param [Hash] attributes Model attributes in the form of hash
56
+ def initialize(attributes = {})
57
+ return unless attributes.is_a?(Hash)
58
+
59
+ # convert string to symbol for hash key
60
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
61
+
62
+ if attributes.has_key?(:'id')
63
+ self.id = attributes[:'id']
64
+ end
65
+
66
+ if attributes.has_key?(:'description')
67
+ self.description = attributes[:'description']
68
+ end
69
+
70
+ if attributes.has_key?(:'enabled')
71
+ self.enabled = attributes[:'enabled']
72
+ end
73
+
74
+ if attributes.has_key?(:'segments')
75
+ if (value = attributes[:'segments']).is_a?(Array)
76
+ self.segments = value
77
+ end
78
+ end
79
+
80
+ if attributes.has_key?(:'variants')
81
+ if (value = attributes[:'variants']).is_a?(Array)
82
+ self.variants = value
83
+ end
84
+ end
85
+
86
+ if attributes.has_key?(:'dataRecordsEnabled')
87
+ self.data_records_enabled = attributes[:'dataRecordsEnabled']
88
+ end
89
+ end
90
+
91
+ # Show invalid properties with the reasons. Usually used together with valid?
92
+ # @return Array for valid properties with the reasons
93
+ def list_invalid_properties
94
+ invalid_properties = Array.new
95
+ if !@id.nil? && @id < 1
96
+ invalid_properties.push('invalid value for "id", must be greater than or equal to 1.')
97
+ end
98
+
99
+ if @description.nil?
100
+ invalid_properties.push('invalid value for "description", description cannot be nil.')
101
+ end
102
+
103
+ if @description.to_s.length < 1
104
+ invalid_properties.push('invalid value for "description", the character length must be great than or equal to 1.')
105
+ end
106
+
107
+ if @enabled.nil?
108
+ invalid_properties.push('invalid value for "enabled", enabled cannot be nil.')
109
+ end
110
+
111
+ if @data_records_enabled.nil?
112
+ invalid_properties.push('invalid value for "data_records_enabled", data_records_enabled cannot be nil.')
113
+ end
114
+
115
+ invalid_properties
116
+ end
117
+
118
+ # Check to see if the all the properties in the model are valid
119
+ # @return true if the model is valid
120
+ def valid?
121
+ return false if !@id.nil? && @id < 1
122
+ return false if @description.nil?
123
+ return false if @description.to_s.length < 1
124
+ return false if @enabled.nil?
125
+ return false if @data_records_enabled.nil?
126
+ true
127
+ end
128
+
129
+ # Custom attribute writer method with validation
130
+ # @param [Object] id Value to be assigned
131
+ def id=(id)
132
+ if !id.nil? && id < 1
133
+ fail ArgumentError, 'invalid value for "id", must be greater than or equal to 1.'
134
+ end
135
+
136
+ @id = id
137
+ end
138
+
139
+ # Custom attribute writer method with validation
140
+ # @param [Object] description Value to be assigned
141
+ def description=(description)
142
+ if description.nil?
143
+ fail ArgumentError, 'description cannot be nil'
144
+ end
145
+
146
+ if description.to_s.length < 1
147
+ fail ArgumentError, 'invalid value for "description", the character length must be great than or equal to 1.'
148
+ end
149
+
150
+ @description = description
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
+ id == o.id &&
159
+ description == o.description &&
160
+ enabled == o.enabled &&
161
+ segments == o.segments &&
162
+ variants == o.variants &&
163
+ data_records_enabled == o.data_records_enabled
164
+ end
165
+
166
+ # @see the `==` method
167
+ # @param [Object] Object to be compared
168
+ def eql?(o)
169
+ self == o
170
+ end
171
+
172
+ # Calculates hash code according to all attributes.
173
+ # @return [Fixnum] Hash code
174
+ def hash
175
+ [id, description, enabled, segments, variants, data_records_enabled].hash
176
+ end
177
+
178
+ # Builds the object from hash
179
+ # @param [Hash] attributes Model attributes in the form of hash
180
+ # @return [Object] Returns the model itself
181
+ def build_from_hash(attributes)
182
+ return nil unless attributes.is_a?(Hash)
183
+ self.class.swagger_types.each_pair do |key, type|
184
+ if type =~ /\AArray<(.*)>/i
185
+ # check to ensure the input is an array given that the the attribute
186
+ # is documented as an array but the input is not
187
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
188
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
189
+ end
190
+ elsif !attributes[self.class.attribute_map[key]].nil?
191
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
192
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
193
+ end
194
+
195
+ self
196
+ end
197
+
198
+ # Deserializes the data based on type
199
+ # @param string type Data type
200
+ # @param string value Value to be deserialized
201
+ # @return [Object] Deserialized data
202
+ def _deserialize(type, value)
203
+ case type.to_sym
204
+ when :DateTime
205
+ DateTime.parse(value)
206
+ when :Date
207
+ Date.parse(value)
208
+ when :String
209
+ value.to_s
210
+ when :Integer
211
+ value.to_i
212
+ when :Float
213
+ value.to_f
214
+ when :BOOLEAN
215
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
216
+ true
217
+ else
218
+ false
219
+ end
220
+ when :Object
221
+ # generic object (usually a Hash), return directly
222
+ value
223
+ when /\AArray<(?<inner_type>.+)>\z/
224
+ inner_type = Regexp.last_match[:inner_type]
225
+ value.map { |v| _deserialize(inner_type, v) }
226
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
227
+ k_type = Regexp.last_match[:k_type]
228
+ v_type = Regexp.last_match[:v_type]
229
+ {}.tap do |hash|
230
+ value.each do |k, v|
231
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
232
+ end
233
+ end
234
+ else # model
235
+ temp_model = Flagr.const_get(type).new
236
+ temp_model.build_from_hash(value)
237
+ end
238
+ end
239
+
240
+ # Returns the string representation of the object
241
+ # @return [String] String presentation of the object
242
+ def to_s
243
+ to_hash.to_s
244
+ end
245
+
246
+ # to_body is an alias to to_hash (backward compatibility)
247
+ # @return [Hash] Returns the object in the form of hash
248
+ def to_body
249
+ to_hash
250
+ end
251
+
252
+ # Returns the object in the form of hash
253
+ # @return [Hash] Returns the object in the form of hash
254
+ def to_hash
255
+ hash = {}
256
+ self.class.attribute_map.each_pair do |attr, param|
257
+ value = self.send(attr)
258
+ next if value.nil?
259
+ hash[param] = _to_hash(value)
260
+ end
261
+ hash
262
+ end
263
+
264
+ # Outputs non-array value in the form of hash
265
+ # For object, use to_hash. Otherwise, just return the value
266
+ # @param [Object] value Any valid value
267
+ # @return [Hash] Returns the value in the form of hash
268
+ def _to_hash(value)
269
+ if value.is_a?(Array)
270
+ value.compact.map { |v| _to_hash(v) }
271
+ elsif value.is_a?(Hash)
272
+ {}.tap do |hash|
273
+ value.each { |k, v| hash[k] = _to_hash(v) }
274
+ end
275
+ elsif value.respond_to? :to_hash
276
+ value.to_hash
277
+ else
278
+ value
279
+ end
280
+ end
281
+ end
282
+ end
@@ -0,0 +1,263 @@
1
+ =begin
2
+ #Flagr
3
+
4
+ #Flagr is a feature flagging, A/B testing and dynamic configuration microservice
5
+
6
+ OpenAPI spec version: 1.0.8
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Flagr
16
+ class FlagSnapshot
17
+ attr_accessor :id
18
+
19
+ attr_accessor :updated_by
20
+
21
+ attr_accessor :flag
22
+
23
+ attr_accessor :updated_at
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :'id' => :'id',
29
+ :'updated_by' => :'updatedBy',
30
+ :'flag' => :'flag',
31
+ :'updated_at' => :'updatedAt'
32
+ }
33
+ end
34
+
35
+ # Attribute type mapping.
36
+ def self.swagger_types
37
+ {
38
+ :'id' => :'Integer',
39
+ :'updated_by' => :'String',
40
+ :'flag' => :'Flag',
41
+ :'updated_at' => :'String'
42
+ }
43
+ end
44
+
45
+ # Initializes the object
46
+ # @param [Hash] attributes Model attributes in the form of hash
47
+ def initialize(attributes = {})
48
+ return unless attributes.is_a?(Hash)
49
+
50
+ # convert string to symbol for hash key
51
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
52
+
53
+ if attributes.has_key?(:'id')
54
+ self.id = attributes[:'id']
55
+ end
56
+
57
+ if attributes.has_key?(:'updatedBy')
58
+ self.updated_by = attributes[:'updatedBy']
59
+ end
60
+
61
+ if attributes.has_key?(:'flag')
62
+ self.flag = attributes[:'flag']
63
+ end
64
+
65
+ if attributes.has_key?(:'updatedAt')
66
+ self.updated_at = attributes[:'updatedAt']
67
+ end
68
+ end
69
+
70
+ # Show invalid properties with the reasons. Usually used together with valid?
71
+ # @return Array for valid properties with the reasons
72
+ def list_invalid_properties
73
+ invalid_properties = Array.new
74
+ if @id.nil?
75
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
76
+ end
77
+
78
+ if @id < 1
79
+ invalid_properties.push('invalid value for "id", must be greater than or equal to 1.')
80
+ end
81
+
82
+ if @flag.nil?
83
+ invalid_properties.push('invalid value for "flag", flag cannot be nil.')
84
+ end
85
+
86
+ if @updated_at.nil?
87
+ invalid_properties.push('invalid value for "updated_at", updated_at cannot be nil.')
88
+ end
89
+
90
+ if @updated_at.to_s.length < 1
91
+ invalid_properties.push('invalid value for "updated_at", the character length must be great than or equal to 1.')
92
+ end
93
+
94
+ invalid_properties
95
+ end
96
+
97
+ # Check to see if the all the properties in the model are valid
98
+ # @return true if the model is valid
99
+ def valid?
100
+ return false if @id.nil?
101
+ return false if @id < 1
102
+ return false if @flag.nil?
103
+ return false if @updated_at.nil?
104
+ return false if @updated_at.to_s.length < 1
105
+ true
106
+ end
107
+
108
+ # Custom attribute writer method with validation
109
+ # @param [Object] id Value to be assigned
110
+ def id=(id)
111
+ if id.nil?
112
+ fail ArgumentError, 'id cannot be nil'
113
+ end
114
+
115
+ if id < 1
116
+ fail ArgumentError, 'invalid value for "id", must be greater than or equal to 1.'
117
+ end
118
+
119
+ @id = id
120
+ end
121
+
122
+ # Custom attribute writer method with validation
123
+ # @param [Object] updated_at Value to be assigned
124
+ def updated_at=(updated_at)
125
+ if updated_at.nil?
126
+ fail ArgumentError, 'updated_at cannot be nil'
127
+ end
128
+
129
+ if updated_at.to_s.length < 1
130
+ fail ArgumentError, 'invalid value for "updated_at", the character length must be great than or equal to 1.'
131
+ end
132
+
133
+ @updated_at = updated_at
134
+ end
135
+
136
+ # Checks equality by comparing each attribute.
137
+ # @param [Object] Object to be compared
138
+ def ==(o)
139
+ return true if self.equal?(o)
140
+ self.class == o.class &&
141
+ id == o.id &&
142
+ updated_by == o.updated_by &&
143
+ flag == o.flag &&
144
+ updated_at == o.updated_at
145
+ end
146
+
147
+ # @see the `==` method
148
+ # @param [Object] Object to be compared
149
+ def eql?(o)
150
+ self == o
151
+ end
152
+
153
+ # Calculates hash code according to all attributes.
154
+ # @return [Fixnum] Hash code
155
+ def hash
156
+ [id, updated_by, flag, updated_at].hash
157
+ end
158
+
159
+ # Builds the object from hash
160
+ # @param [Hash] attributes Model attributes in the form of hash
161
+ # @return [Object] Returns the model itself
162
+ def build_from_hash(attributes)
163
+ return nil unless attributes.is_a?(Hash)
164
+ self.class.swagger_types.each_pair do |key, type|
165
+ if type =~ /\AArray<(.*)>/i
166
+ # check to ensure the input is an array given that the the attribute
167
+ # is documented as an array but the input is not
168
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
169
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
170
+ end
171
+ elsif !attributes[self.class.attribute_map[key]].nil?
172
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
173
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
174
+ end
175
+
176
+ self
177
+ end
178
+
179
+ # Deserializes the data based on type
180
+ # @param string type Data type
181
+ # @param string value Value to be deserialized
182
+ # @return [Object] Deserialized data
183
+ def _deserialize(type, value)
184
+ case type.to_sym
185
+ when :DateTime
186
+ DateTime.parse(value)
187
+ when :Date
188
+ Date.parse(value)
189
+ when :String
190
+ value.to_s
191
+ when :Integer
192
+ value.to_i
193
+ when :Float
194
+ value.to_f
195
+ when :BOOLEAN
196
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
197
+ true
198
+ else
199
+ false
200
+ end
201
+ when :Object
202
+ # generic object (usually a Hash), return directly
203
+ value
204
+ when /\AArray<(?<inner_type>.+)>\z/
205
+ inner_type = Regexp.last_match[:inner_type]
206
+ value.map { |v| _deserialize(inner_type, v) }
207
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
208
+ k_type = Regexp.last_match[:k_type]
209
+ v_type = Regexp.last_match[:v_type]
210
+ {}.tap do |hash|
211
+ value.each do |k, v|
212
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
213
+ end
214
+ end
215
+ else # model
216
+ temp_model = Flagr.const_get(type).new
217
+ temp_model.build_from_hash(value)
218
+ end
219
+ end
220
+
221
+ # Returns the string representation of the object
222
+ # @return [String] String presentation of the object
223
+ def to_s
224
+ to_hash.to_s
225
+ end
226
+
227
+ # to_body is an alias to to_hash (backward compatibility)
228
+ # @return [Hash] Returns the object in the form of hash
229
+ def to_body
230
+ to_hash
231
+ end
232
+
233
+ # Returns the object in the form of hash
234
+ # @return [Hash] Returns the object in the form of hash
235
+ def to_hash
236
+ hash = {}
237
+ self.class.attribute_map.each_pair do |attr, param|
238
+ value = self.send(attr)
239
+ next if value.nil?
240
+ hash[param] = _to_hash(value)
241
+ end
242
+ hash
243
+ end
244
+
245
+ # Outputs non-array value in the form of hash
246
+ # For object, use to_hash. Otherwise, just return the value
247
+ # @param [Object] value Any valid value
248
+ # @return [Hash] Returns the value in the form of hash
249
+ def _to_hash(value)
250
+ if value.is_a?(Array)
251
+ value.compact.map { |v| _to_hash(v) }
252
+ elsif value.is_a?(Hash)
253
+ {}.tap do |hash|
254
+ value.each { |k, v| hash[k] = _to_hash(v) }
255
+ end
256
+ elsif value.respond_to? :to_hash
257
+ value.to_hash
258
+ else
259
+ value
260
+ end
261
+ end
262
+ end
263
+ end