class2 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes +4 -0
- data/lib/class2.rb +8 -5
- data/lib/class2/version.rb +1 -1
- 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: 3f3e7cc958f7403b58f19b0694d665ee99c9797f
|
4
|
+
data.tar.gz: b92c91959b8076615445b117c5fd83d6136d406d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0609d0e99bb48816a8b76776fbe2ea520d5a501c345541cec97d5c59cf28645aa5e8177720219b1e1363d2d546fd30ffa81b68321a0ceccbcbcb2cdef4a715a2
|
7
|
+
data.tar.gz: f4d34009b4521d50d2f97b654889028b119ea8a1c81ea0a65f4fed487aa089c2add5a8ac36d58311e0a04db823d1507d5a990dba9e336e9154fec798fdfddd60
|
data/Changes
CHANGED
data/lib/class2.rb
CHANGED
@@ -127,17 +127,20 @@ class Class2
|
|
127
127
|
def to_h
|
128
128
|
hash = {}
|
129
129
|
(#{simple.map { |n| n.keys.first } + nested.map { |n| n.keys.first }}).each do |name|
|
130
|
-
hash[name] = public_send(name)
|
131
|
-
|
130
|
+
hash[name] = v = public_send(name)
|
131
|
+
# Don't turn nil into a Hash
|
132
|
+
next if v.nil? || !v.respond_to?(:to_h)
|
133
|
+
# Don't turn empty Arrays into a Hash
|
134
|
+
next if v.is_a?(Array) && v.empty?
|
132
135
|
|
133
136
|
errors = [ ArgumentError, TypeError ]
|
134
137
|
# Seems needlessly complicated, why doesn't Hash() do some of this?
|
135
138
|
begin
|
136
|
-
hash[name] =
|
139
|
+
hash[name] = v.to_h
|
137
140
|
# to_h is dependent on its contents
|
138
141
|
rescue *errors
|
139
|
-
next unless
|
140
|
-
hash[name] =
|
142
|
+
next unless v.is_a?(Enumerable)
|
143
|
+
hash[name] = v.map do |e|
|
141
144
|
begin
|
142
145
|
e.respond_to?(:to_h) ? e.to_h : e
|
143
146
|
rescue *errors
|
data/lib/class2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Skye Shaw
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|