class_kit 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/class_kit/helper.rb +26 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c4c2e5ad372e1f531c744504badf4e475b4da8e
|
4
|
+
data.tar.gz: 2db318e1138a6917be292c7111c02c0422d30156
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f595e18e28fa3f59f2763e8df1f5dc6d3a7ec04f662187bc5ef60d8d9b676a7a7c0d05039ef9a182f22b350512d2cc7bf47f95538801996f8ca357185be14bc
|
7
|
+
data.tar.gz: a169b775d07a1ae826ead253d4740058419da04cd204bb4100479fb0b07f47705f824a8dd0daaae2f4bbc11e2bc359ad17e4e513471df84dfee8af091436e472
|
data/lib/class_kit/helper.rb
CHANGED
@@ -20,7 +20,31 @@ module ClassKit
|
|
20
20
|
def to_hash(object)
|
21
21
|
validate_class_kit(object.class)
|
22
22
|
|
23
|
-
|
23
|
+
hash = {}
|
24
|
+
|
25
|
+
attributes = @attribute_helper.get_attributes(object.class)
|
26
|
+
attributes.each do |attribute|
|
27
|
+
key = attribute[:name]
|
28
|
+
type = attribute[:type]
|
29
|
+
value = object.public_send(key)
|
30
|
+
if value != nil
|
31
|
+
hash[key] = if is_class_kit?(type)
|
32
|
+
to_hash(value)
|
33
|
+
elsif type == Array
|
34
|
+
value.map do |i|
|
35
|
+
if is_class_kit?(i.class)
|
36
|
+
to_hash(i)
|
37
|
+
else
|
38
|
+
i
|
39
|
+
end
|
40
|
+
end
|
41
|
+
else
|
42
|
+
value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
@hash_helper.indifferent!(hash)
|
47
|
+
hash
|
24
48
|
end
|
25
49
|
|
26
50
|
#This method is called to convert a Hash into a ClassKit object.
|
@@ -63,7 +87,7 @@ module ClassKit
|
|
63
87
|
|
64
88
|
#This method is called to convert a ClassKit object into JSON.
|
65
89
|
def to_json(object)
|
66
|
-
hash =
|
90
|
+
hash = to_hash(object)
|
67
91
|
JSON.dump(hash)
|
68
92
|
end
|
69
93
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sage One
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|