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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c341f88fcae9e17d3559a0fd80af645c4d313269f20f1a642c546f8250f46285
4
- data.tar.gz: 06a26fa2af6d2739c486abc7022c1fba8f330d420e390982f5b6313cd972e245
3
+ metadata.gz: af9dbd1ca9cb360970e4759f0576b56804aad529d47dfd6befeeb9c555c600b7
4
+ data.tar.gz: be991673275fbe69133a4bb8ba0c54dc8e5d889912b3b7075b1d19b5c0e4dbac
5
5
  SHA512:
6
- metadata.gz: 40ce27f5355d4f69afb366f7fba54cf68526844f0ea73739ff86cd132527a18b682298b475a193fa5005e7488fa1e953015159883c09487cd1876f7b712c3de2
7
- data.tar.gz: d5f9175a10aec8959b7c699cdba506ec4fb699a356b036b8aa6b3c55dd3cc7179715eb565d5775e8ea49a7e428b7daa126c391788572ca78784981c75f21ecb8
6
+ metadata.gz: ac50ee8e3972a1ced70e2bafaf096755e0dbfca991f00227fe52ea5f8fc0980c751ffd455cde9144dfc5eecf95709e340d0a4d426ba9fbd921d61257fc98f26e
7
+ data.tar.gz: 90710da92404a2705586b75df7defecde3851f20ad7c1e47b6eb9d0a89081610dfcc2c77f316014f5200432e85c55edf8ff96cccd042aa15eb254130cd441d8e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.80)
4
+ istox (0.1.81.pre.test2)
5
5
  binding_of_caller
6
6
  bunny (>= 2.12.0)
7
7
  graphlient
@@ -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.process_hash(_parent, my_hash)
20
- my_hash.each do |key, value|
21
- if value.is_a?(Hash)
22
- process_hash(key, value)
23
- elsif value.is_a?(Array)
24
- my_hash[key] = value.map do |item|
25
- process_hash(nil, item.to_h)
26
- end
27
- else
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.to_h.transform_values do |v|
65
- v.is_a?(OpenStruct) ? deep_to_h(v) : v
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
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.81-test1'.freeze
2
+ VERSION = '0.1.81-test2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: istox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.81.pre.test1
4
+ version: 0.1.81.pre.test2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siong Leng