influxdb-client 2.4.0.pre.4589 → 2.4.0.pre.4872
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +21 -21
- data/lib/influxdb-client.rb +7 -0
- data/lib/influxdb2/client/client.rb +7 -0
- data/lib/influxdb2/client/default_api.rb +8 -13
- data/lib/influxdb2/client/delete_api.rb +1 -1
- data/lib/influxdb2/client/flux_csv_parser.rb +21 -2
- data/lib/influxdb2/client/health_api.rb +1 -1
- data/lib/influxdb2/client/invocable_scripts_api.rb +147 -0
- data/lib/influxdb2/client/models/script.rb +299 -0
- data/lib/influxdb2/client/models/script_create_request.rb +259 -0
- data/lib/influxdb2/client/models/script_invocation_params.rb +210 -0
- data/lib/influxdb2/client/models/script_language.rb +36 -0
- data/lib/influxdb2/client/models/script_update_request.rb +229 -0
- data/lib/influxdb2/client/models/scripts.rb +212 -0
- data/lib/influxdb2/client/ping_api.rb +1 -1
- data/lib/influxdb2/client/query_api.rb +2 -2
- data/test/influxdb/client_test.rb +1 -1
- data/test/influxdb/flux_csv_parser_test.rb +17 -0
- data/test/influxdb/invocable_scripts_api_test.rb +41 -0
- metadata +11 -2
@@ -0,0 +1,299 @@
|
|
1
|
+
=begin
|
2
|
+
#InfluxDB OSS API Service
|
3
|
+
|
4
|
+
#The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 2.0.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
|
10
|
+
=end
|
11
|
+
|
12
|
+
require 'date'
|
13
|
+
require 'set'
|
14
|
+
require 'time'
|
15
|
+
|
16
|
+
module InfluxDB2
|
17
|
+
class Script
|
18
|
+
attr_accessor :id
|
19
|
+
|
20
|
+
attr_accessor :name
|
21
|
+
|
22
|
+
attr_accessor :description
|
23
|
+
|
24
|
+
attr_accessor :org_id
|
25
|
+
|
26
|
+
# script to be executed
|
27
|
+
attr_accessor :script
|
28
|
+
|
29
|
+
attr_accessor :language
|
30
|
+
|
31
|
+
# invocation endpoint address
|
32
|
+
attr_accessor :url
|
33
|
+
|
34
|
+
attr_accessor :created_at
|
35
|
+
|
36
|
+
attr_accessor :updated_at
|
37
|
+
|
38
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
39
|
+
def self.attribute_map
|
40
|
+
{
|
41
|
+
:'id' => :'id',
|
42
|
+
:'name' => :'name',
|
43
|
+
:'description' => :'description',
|
44
|
+
:'org_id' => :'orgID',
|
45
|
+
:'script' => :'script',
|
46
|
+
:'language' => :'language',
|
47
|
+
:'url' => :'url',
|
48
|
+
:'created_at' => :'createdAt',
|
49
|
+
:'updated_at' => :'updatedAt',
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
# Attribute type mapping.
|
54
|
+
def self.openapi_types
|
55
|
+
{
|
56
|
+
:'id' => :'String',
|
57
|
+
:'name' => :'String',
|
58
|
+
:'description' => :'String',
|
59
|
+
:'org_id' => :'String',
|
60
|
+
:'script' => :'String',
|
61
|
+
:'language' => :'ScriptLanguage',
|
62
|
+
:'url' => :'String',
|
63
|
+
:'created_at' => :'Time',
|
64
|
+
:'updated_at' => :'Time'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# List of attributes with nullable: true
|
69
|
+
def self.openapi_nullable
|
70
|
+
Set.new([
|
71
|
+
])
|
72
|
+
end
|
73
|
+
|
74
|
+
# Initializes the object
|
75
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
76
|
+
def initialize(attributes = {})
|
77
|
+
if (!attributes.is_a?(Hash))
|
78
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `InfluxDB2::Script` initialize method"
|
79
|
+
end
|
80
|
+
|
81
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
82
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
83
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
84
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `InfluxDB2::Script`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
85
|
+
end
|
86
|
+
h[k.to_sym] = v
|
87
|
+
}
|
88
|
+
|
89
|
+
if attributes.key?(:'id')
|
90
|
+
self.id = attributes[:'id']
|
91
|
+
end
|
92
|
+
|
93
|
+
if attributes.key?(:'name')
|
94
|
+
self.name = attributes[:'name']
|
95
|
+
end
|
96
|
+
|
97
|
+
if attributes.key?(:'description')
|
98
|
+
self.description = attributes[:'description']
|
99
|
+
end
|
100
|
+
|
101
|
+
if attributes.key?(:'org_id')
|
102
|
+
self.org_id = attributes[:'org_id']
|
103
|
+
end
|
104
|
+
|
105
|
+
if attributes.key?(:'script')
|
106
|
+
self.script = attributes[:'script']
|
107
|
+
end
|
108
|
+
|
109
|
+
if attributes.key?(:'language')
|
110
|
+
self.language = attributes[:'language']
|
111
|
+
end
|
112
|
+
|
113
|
+
if attributes.key?(:'url')
|
114
|
+
self.url = attributes[:'url']
|
115
|
+
end
|
116
|
+
|
117
|
+
if attributes.key?(:'created_at')
|
118
|
+
self.created_at = attributes[:'created_at']
|
119
|
+
end
|
120
|
+
|
121
|
+
if attributes.key?(:'updated_at')
|
122
|
+
self.updated_at = attributes[:'updated_at']
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
127
|
+
# @return Array for valid properties with the reasons
|
128
|
+
def list_invalid_properties
|
129
|
+
invalid_properties = Array.new
|
130
|
+
if @name.nil?
|
131
|
+
invalid_properties.push('invalid value for "name", name cannot be nil.')
|
132
|
+
end
|
133
|
+
|
134
|
+
if @org_id.nil?
|
135
|
+
invalid_properties.push('invalid value for "org_id", org_id cannot be nil.')
|
136
|
+
end
|
137
|
+
|
138
|
+
if @script.nil?
|
139
|
+
invalid_properties.push('invalid value for "script", script cannot be nil.')
|
140
|
+
end
|
141
|
+
|
142
|
+
invalid_properties
|
143
|
+
end
|
144
|
+
|
145
|
+
# Check to see if the all the properties in the model are valid
|
146
|
+
# @return true if the model is valid
|
147
|
+
def valid?
|
148
|
+
return false if @name.nil?
|
149
|
+
return false if @org_id.nil?
|
150
|
+
return false if @script.nil?
|
151
|
+
true
|
152
|
+
end
|
153
|
+
|
154
|
+
# Checks equality by comparing each attribute.
|
155
|
+
# @param [Object] Object to be compared
|
156
|
+
def ==(o)
|
157
|
+
return true if self.equal?(o)
|
158
|
+
self.class == o.class &&
|
159
|
+
id == o.id &&
|
160
|
+
name == o.name &&
|
161
|
+
description == o.description &&
|
162
|
+
org_id == o.org_id &&
|
163
|
+
script == o.script &&
|
164
|
+
language == o.language &&
|
165
|
+
url == o.url &&
|
166
|
+
created_at == o.created_at &&
|
167
|
+
updated_at == o.updated_at
|
168
|
+
end
|
169
|
+
|
170
|
+
# @see the `==` method
|
171
|
+
# @param [Object] Object to be compared
|
172
|
+
def eql?(o)
|
173
|
+
self == o
|
174
|
+
end
|
175
|
+
|
176
|
+
# Calculates hash code according to all attributes.
|
177
|
+
# @return [Integer] Hash code
|
178
|
+
def hash
|
179
|
+
[id, name, description, org_id, script, language, url, created_at, updated_at].hash
|
180
|
+
end
|
181
|
+
|
182
|
+
# Builds the object from hash
|
183
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
184
|
+
# @return [Object] Returns the model itself
|
185
|
+
def self.build_from_hash(attributes)
|
186
|
+
new.build_from_hash(attributes)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Builds the object from hash
|
190
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
191
|
+
# @return [Object] Returns the model itself
|
192
|
+
def build_from_hash(attributes)
|
193
|
+
return nil unless attributes.is_a?(Hash)
|
194
|
+
self.class.openapi_types.each_pair do |key, type|
|
195
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
196
|
+
self.send("#{key}=", nil)
|
197
|
+
elsif type =~ /\AArray<(.*)>/i
|
198
|
+
# check to ensure the input is an array given that the attribute
|
199
|
+
# is documented as an array but the input is not
|
200
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
201
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
202
|
+
end
|
203
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
204
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
self
|
209
|
+
end
|
210
|
+
|
211
|
+
# Deserializes the data based on type
|
212
|
+
# @param string type Data type
|
213
|
+
# @param string value Value to be deserialized
|
214
|
+
# @return [Object] Deserialized data
|
215
|
+
def _deserialize(type, value)
|
216
|
+
case type.to_sym
|
217
|
+
when :Time
|
218
|
+
Time.parse(value)
|
219
|
+
when :Date
|
220
|
+
Date.parse(value)
|
221
|
+
when :String
|
222
|
+
value.to_s
|
223
|
+
when :Integer
|
224
|
+
value.to_i
|
225
|
+
when :Float
|
226
|
+
value.to_f
|
227
|
+
when :Boolean
|
228
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
229
|
+
true
|
230
|
+
else
|
231
|
+
false
|
232
|
+
end
|
233
|
+
when :Object
|
234
|
+
# generic object (usually a Hash), return directly
|
235
|
+
value
|
236
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
237
|
+
inner_type = Regexp.last_match[:inner_type]
|
238
|
+
value.map { |v| _deserialize(inner_type, v) }
|
239
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
240
|
+
k_type = Regexp.last_match[:k_type]
|
241
|
+
v_type = Regexp.last_match[:v_type]
|
242
|
+
{}.tap do |hash|
|
243
|
+
value.each do |k, v|
|
244
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
else # model
|
248
|
+
InfluxDB2.const_get(type).build_from_hash(value)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
# Returns the string representation of the object
|
253
|
+
# @return [String] String presentation of the object
|
254
|
+
def to_s
|
255
|
+
to_hash.to_s
|
256
|
+
end
|
257
|
+
|
258
|
+
# to_body is an alias to to_hash (backward compatibility)
|
259
|
+
# @return [Hash] Returns the object in the form of hash
|
260
|
+
def to_body
|
261
|
+
to_hash
|
262
|
+
end
|
263
|
+
|
264
|
+
# Returns the object in the form of hash
|
265
|
+
# @return [Hash] Returns the object in the form of hash
|
266
|
+
def to_hash
|
267
|
+
hash = {}
|
268
|
+
self.class.attribute_map.each_pair do |attr, param|
|
269
|
+
value = self.send(attr)
|
270
|
+
if value.nil?
|
271
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
272
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
273
|
+
end
|
274
|
+
|
275
|
+
hash[param] = _to_hash(value)
|
276
|
+
end
|
277
|
+
hash
|
278
|
+
end
|
279
|
+
|
280
|
+
# Outputs non-array value in the form of hash
|
281
|
+
# For object, use to_hash. Otherwise, just return the value
|
282
|
+
# @param [Object] value Any valid value
|
283
|
+
# @return [Hash] Returns the value in the form of hash
|
284
|
+
def _to_hash(value)
|
285
|
+
if value.is_a?(Array)
|
286
|
+
value.compact.map { |v| _to_hash(v) }
|
287
|
+
elsif value.is_a?(Hash)
|
288
|
+
{}.tap do |hash|
|
289
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
290
|
+
end
|
291
|
+
elsif value.respond_to? :to_hash
|
292
|
+
value.to_hash
|
293
|
+
else
|
294
|
+
value
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
end
|
@@ -0,0 +1,259 @@
|
|
1
|
+
=begin
|
2
|
+
#InfluxDB OSS API Service
|
3
|
+
|
4
|
+
#The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 2.0.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
|
10
|
+
=end
|
11
|
+
|
12
|
+
require 'date'
|
13
|
+
require 'set'
|
14
|
+
require 'time'
|
15
|
+
|
16
|
+
module InfluxDB2
|
17
|
+
class ScriptCreateRequest
|
18
|
+
# The name of the script. The name must be unique within the organization.
|
19
|
+
attr_accessor :name
|
20
|
+
|
21
|
+
attr_accessor :description
|
22
|
+
|
23
|
+
# The script to execute.
|
24
|
+
attr_accessor :script
|
25
|
+
|
26
|
+
attr_accessor :language
|
27
|
+
|
28
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
29
|
+
def self.attribute_map
|
30
|
+
{
|
31
|
+
:'name' => :'name',
|
32
|
+
:'description' => :'description',
|
33
|
+
:'script' => :'script',
|
34
|
+
:'language' => :'language',
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
# Attribute type mapping.
|
39
|
+
def self.openapi_types
|
40
|
+
{
|
41
|
+
:'name' => :'String',
|
42
|
+
:'description' => :'String',
|
43
|
+
:'script' => :'String',
|
44
|
+
:'language' => :'ScriptLanguage'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
# List of attributes with nullable: true
|
49
|
+
def self.openapi_nullable
|
50
|
+
Set.new([
|
51
|
+
])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Initializes the object
|
55
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
56
|
+
def initialize(attributes = {})
|
57
|
+
if (!attributes.is_a?(Hash))
|
58
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `InfluxDB2::ScriptCreateRequest` initialize method"
|
59
|
+
end
|
60
|
+
|
61
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
62
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
63
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
64
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `InfluxDB2::ScriptCreateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
65
|
+
end
|
66
|
+
h[k.to_sym] = v
|
67
|
+
}
|
68
|
+
|
69
|
+
if attributes.key?(:'name')
|
70
|
+
self.name = attributes[:'name']
|
71
|
+
end
|
72
|
+
|
73
|
+
if attributes.key?(:'description')
|
74
|
+
self.description = attributes[:'description']
|
75
|
+
end
|
76
|
+
|
77
|
+
if attributes.key?(:'script')
|
78
|
+
self.script = attributes[:'script']
|
79
|
+
end
|
80
|
+
|
81
|
+
if attributes.key?(:'language')
|
82
|
+
self.language = attributes[:'language']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
87
|
+
# @return Array for valid properties with the reasons
|
88
|
+
def list_invalid_properties
|
89
|
+
invalid_properties = Array.new
|
90
|
+
if @name.nil?
|
91
|
+
invalid_properties.push('invalid value for "name", name cannot be nil.')
|
92
|
+
end
|
93
|
+
|
94
|
+
if @description.nil?
|
95
|
+
invalid_properties.push('invalid value for "description", description cannot be nil.')
|
96
|
+
end
|
97
|
+
|
98
|
+
if @script.nil?
|
99
|
+
invalid_properties.push('invalid value for "script", script cannot be nil.')
|
100
|
+
end
|
101
|
+
|
102
|
+
if @language.nil?
|
103
|
+
invalid_properties.push('invalid value for "language", language cannot be nil.')
|
104
|
+
end
|
105
|
+
|
106
|
+
invalid_properties
|
107
|
+
end
|
108
|
+
|
109
|
+
# Check to see if the all the properties in the model are valid
|
110
|
+
# @return true if the model is valid
|
111
|
+
def valid?
|
112
|
+
return false if @name.nil?
|
113
|
+
return false if @description.nil?
|
114
|
+
return false if @script.nil?
|
115
|
+
return false if @language.nil?
|
116
|
+
true
|
117
|
+
end
|
118
|
+
|
119
|
+
# Checks equality by comparing each attribute.
|
120
|
+
# @param [Object] Object to be compared
|
121
|
+
def ==(o)
|
122
|
+
return true if self.equal?(o)
|
123
|
+
self.class == o.class &&
|
124
|
+
name == o.name &&
|
125
|
+
description == o.description &&
|
126
|
+
script == o.script &&
|
127
|
+
language == o.language
|
128
|
+
end
|
129
|
+
|
130
|
+
# @see the `==` method
|
131
|
+
# @param [Object] Object to be compared
|
132
|
+
def eql?(o)
|
133
|
+
self == o
|
134
|
+
end
|
135
|
+
|
136
|
+
# Calculates hash code according to all attributes.
|
137
|
+
# @return [Integer] Hash code
|
138
|
+
def hash
|
139
|
+
[name, description, script, language].hash
|
140
|
+
end
|
141
|
+
|
142
|
+
# Builds the object from hash
|
143
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
144
|
+
# @return [Object] Returns the model itself
|
145
|
+
def self.build_from_hash(attributes)
|
146
|
+
new.build_from_hash(attributes)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Builds the object from hash
|
150
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
151
|
+
# @return [Object] Returns the model itself
|
152
|
+
def build_from_hash(attributes)
|
153
|
+
return nil unless attributes.is_a?(Hash)
|
154
|
+
self.class.openapi_types.each_pair do |key, type|
|
155
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
156
|
+
self.send("#{key}=", nil)
|
157
|
+
elsif type =~ /\AArray<(.*)>/i
|
158
|
+
# check to ensure the input is an array given that the attribute
|
159
|
+
# is documented as an array but the input is not
|
160
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
161
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
162
|
+
end
|
163
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
164
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
self
|
169
|
+
end
|
170
|
+
|
171
|
+
# Deserializes the data based on type
|
172
|
+
# @param string type Data type
|
173
|
+
# @param string value Value to be deserialized
|
174
|
+
# @return [Object] Deserialized data
|
175
|
+
def _deserialize(type, value)
|
176
|
+
case type.to_sym
|
177
|
+
when :Time
|
178
|
+
Time.parse(value)
|
179
|
+
when :Date
|
180
|
+
Date.parse(value)
|
181
|
+
when :String
|
182
|
+
value.to_s
|
183
|
+
when :Integer
|
184
|
+
value.to_i
|
185
|
+
when :Float
|
186
|
+
value.to_f
|
187
|
+
when :Boolean
|
188
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
189
|
+
true
|
190
|
+
else
|
191
|
+
false
|
192
|
+
end
|
193
|
+
when :Object
|
194
|
+
# generic object (usually a Hash), return directly
|
195
|
+
value
|
196
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
197
|
+
inner_type = Regexp.last_match[:inner_type]
|
198
|
+
value.map { |v| _deserialize(inner_type, v) }
|
199
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
200
|
+
k_type = Regexp.last_match[:k_type]
|
201
|
+
v_type = Regexp.last_match[:v_type]
|
202
|
+
{}.tap do |hash|
|
203
|
+
value.each do |k, v|
|
204
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
else # model
|
208
|
+
InfluxDB2.const_get(type).build_from_hash(value)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Returns the string representation of the object
|
213
|
+
# @return [String] String presentation of the object
|
214
|
+
def to_s
|
215
|
+
to_hash.to_s
|
216
|
+
end
|
217
|
+
|
218
|
+
# to_body is an alias to to_hash (backward compatibility)
|
219
|
+
# @return [Hash] Returns the object in the form of hash
|
220
|
+
def to_body
|
221
|
+
to_hash
|
222
|
+
end
|
223
|
+
|
224
|
+
# Returns the object in the form of hash
|
225
|
+
# @return [Hash] Returns the object in the form of hash
|
226
|
+
def to_hash
|
227
|
+
hash = {}
|
228
|
+
self.class.attribute_map.each_pair do |attr, param|
|
229
|
+
value = self.send(attr)
|
230
|
+
if value.nil?
|
231
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
232
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
233
|
+
end
|
234
|
+
|
235
|
+
hash[param] = _to_hash(value)
|
236
|
+
end
|
237
|
+
hash
|
238
|
+
end
|
239
|
+
|
240
|
+
# Outputs non-array value in the form of hash
|
241
|
+
# For object, use to_hash. Otherwise, just return the value
|
242
|
+
# @param [Object] value Any valid value
|
243
|
+
# @return [Hash] Returns the value in the form of hash
|
244
|
+
def _to_hash(value)
|
245
|
+
if value.is_a?(Array)
|
246
|
+
value.compact.map { |v| _to_hash(v) }
|
247
|
+
elsif value.is_a?(Hash)
|
248
|
+
{}.tap do |hash|
|
249
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
250
|
+
end
|
251
|
+
elsif value.respond_to? :to_hash
|
252
|
+
value.to_hash
|
253
|
+
else
|
254
|
+
value
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
end
|