class_kit 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/class_kit/helper.rb +26 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e73454f0878765e15f8b77a294f45fe32a167e7b
4
- data.tar.gz: 50f2d0108ebcdeba1f3722626c9626b5acb17bdd
3
+ metadata.gz: 4c4c2e5ad372e1f531c744504badf4e475b4da8e
4
+ data.tar.gz: 2db318e1138a6917be292c7111c02c0422d30156
5
5
  SHA512:
6
- metadata.gz: 981d42396af504fe48500d6f36546e667c2a176e3916b39f5a62d07fabd9ed4aab69c7552ce1cc9368bdd160f37005124ded06e6d220e9485f61f48cd1791d81
7
- data.tar.gz: 1d6895a80153caeb8dada828824964daabc5052731e817ac3c27f5d02c560f69ac85fce0d456afd4c4b8f3cd0e2c46bd60cd1e9bcb7e7dc10d065c227f45d79a
6
+ metadata.gz: 8f595e18e28fa3f59f2763e8df1f5dc6d3a7ec04f662187bc5ef60d8d9b676a7a7c0d05039ef9a182f22b350512d2cc7bf47f95538801996f8ca357185be14bc
7
+ data.tar.gz: a169b775d07a1ae826ead253d4740058419da04cd204bb4100479fb0b07f47705f824a8dd0daaae2f4bbc11e2bc359ad17e4e513471df84dfee8af091436e472
@@ -20,7 +20,31 @@ module ClassKit
20
20
  def to_hash(object)
21
21
  validate_class_kit(object.class)
22
22
 
23
- @hash_helper.to_hash(object)
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 = @hash_helper.to_hash(object)
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.3.1
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-06-30 00:00:00.000000000 Z
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler