istox 0.1.81.pre.test1 → 0.1.81.pre.test2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/istox/helpers/common_helper.rb +25 -45
- data/lib/istox/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af9dbd1ca9cb360970e4759f0576b56804aad529d47dfd6befeeb9c555c600b7
|
4
|
+
data.tar.gz: be991673275fbe69133a4bb8ba0c54dc8e5d889912b3b7075b1d19b5c0e4dbac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac50ee8e3972a1ced70e2bafaf096755e0dbfca991f00227fe52ea5f8fc0980c751ffd455cde9144dfc5eecf95709e340d0a4d426ba9fbd921d61257fc98f26e
|
7
|
+
data.tar.gz: 90710da92404a2705586b75df7defecde3851f20ad7c1e47b6eb9d0a89081610dfcc2c77f316014f5200432e85c55edf8ff96cccd042aa15eb254130cd441d8e
|
data/Gemfile.lock
CHANGED
@@ -6,63 +6,43 @@ module Istox
|
|
6
6
|
if model.is_a?(Array)
|
7
7
|
model.map do |item|
|
8
8
|
hash = deep_to_h(item).deep_transform_keys { |key| key.to_s.underscore.to_sym }
|
9
|
-
process_hash(nil, hash)
|
9
|
+
# process_hash(nil, hash)
|
10
|
+
|
11
|
+
puts hash.inspect
|
10
12
|
to_recursive_ostruct(hash)
|
11
13
|
end
|
12
14
|
else
|
13
15
|
hash = deep_to_h(model).deep_transform_keys { |key| key.to_s.underscore.to_sym }
|
14
|
-
process_hash(nil, hash)
|
16
|
+
# process_hash(nil, hash)
|
15
17
|
to_recursive_ostruct(hash)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def self.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
my_hash[key] = value
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# def self.add_methods(ostruct)
|
34
|
-
# hashmap = ostruct.to_h
|
35
|
-
|
36
|
-
# hashmap&.each do |k, _v|
|
37
|
-
# # add_method k.to_s do
|
38
|
-
# ostruct.send(k.to_s)
|
39
|
-
# # end
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
|
43
|
-
def self.to_recursive_ostruct(hash)
|
44
|
-
::Istox::MyOpenStruct.new(hash.each_with_object({}) do |(key, val), memo|
|
45
|
-
memo[key] = if val.is_a?(Hash)
|
46
|
-
to_open_struct(val)
|
47
|
-
elsif val.is_a?(Array)
|
48
|
-
val.map do |item|
|
49
|
-
to_open_struct(item)
|
50
|
-
end
|
51
|
-
else
|
52
|
-
val
|
53
|
-
end
|
54
|
-
end)
|
55
|
-
end
|
56
|
-
|
57
|
-
def add_method(name, &block)
|
58
|
-
(class << self; self; end).class_eval do
|
59
|
-
define_method name, &block
|
21
|
+
def self.to_recursive_ostruct(obj)
|
22
|
+
if obj.is_a?(Hash)
|
23
|
+
::Istox::MyOpenStruct.new(obj.map { |key, val| [key, to_recursive_ostruct(val)] }.to_h)
|
24
|
+
elsif obj.is_a?(Array)
|
25
|
+
obj.map { |o| to_recursive_ostruct(o) }
|
26
|
+
elsif obj.is_a?(OpenStruct)
|
27
|
+
::Istox::MyOpenStruct.new(obj)
|
28
|
+
else # Assumed to be a primitive value
|
29
|
+
obj
|
60
30
|
end
|
61
31
|
end
|
62
32
|
|
63
33
|
def self.deep_to_h(obj)
|
64
|
-
obj.
|
65
|
-
|
34
|
+
if obj.is_a?(OpenStruct) || obj.is_a?(Hash)
|
35
|
+
obj.to_h.transform_values do |v|
|
36
|
+
if v.is_a?(OpenStruct) || v.is_a?(Array)
|
37
|
+
deep_to_h(v)
|
38
|
+
else
|
39
|
+
v
|
40
|
+
end
|
41
|
+
end
|
42
|
+
elsif obj.is_a?(Array)
|
43
|
+
obj.map { |r| deep_to_h(r) }
|
44
|
+
else
|
45
|
+
obj
|
66
46
|
end
|
67
47
|
end
|
68
48
|
end
|
data/lib/istox/version.rb
CHANGED