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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7671575eba7274b6b325b522c133daeaf250f9ee
4
- data.tar.gz: 9da2448df22a465c53201c23441a1142bc86d3bd
3
+ metadata.gz: 3f3e7cc958f7403b58f19b0694d665ee99c9797f
4
+ data.tar.gz: b92c91959b8076615445b117c5fd83d6136d406d
5
5
  SHA512:
6
- metadata.gz: 3aa91695a4eab4393fb211ec0d5582383e69e9e183728a532f4e5fe4c6d2f25d809f2e86e857299935ce5a216b790063dadb0281198a19c94952719b082cc901
7
- data.tar.gz: be3aa3f33af4db98178ca53c056c143f1cfc5a3eef70d8d62ca49578c11beadf9d18212290f02e8571737d44f3f7647acba9afabf37c4a442326a014a2dffd82
6
+ metadata.gz: 0609d0e99bb48816a8b76776fbe2ea520d5a501c345541cec97d5c59cf28645aa5e8177720219b1e1363d2d546fd30ffa81b68321a0ceccbcbcb2cdef4a715a2
7
+ data.tar.gz: f4d34009b4521d50d2f97b654889028b119ea8a1c81ea0a65f4fed487aa089c2add5a8ac36d58311e0a04db823d1507d5a990dba9e336e9154fec798fdfddd60
data/Changes CHANGED
@@ -1,3 +1,7 @@
1
+ 2017-09-23 v0.2.1
2
+ --------------------
3
+ * Bug fix: to_h values should not always be a Hash
4
+
1
5
  2017-09-14 v0.2.0
2
6
  --------------------
3
7
  * Add class2 method
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
- next unless hash[name].respond_to?(:to_h)
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] = hash[name].to_h
139
+ hash[name] = v.to_h
137
140
  # to_h is dependent on its contents
138
141
  rescue *errors
139
- next unless hash[name].is_a?(Enumerable)
140
- hash[name] = hash[name].map do |e|
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
@@ -1,3 +1,3 @@
1
1
  class Class2
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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-15 00:00:00.000000000 Z
11
+ date: 2017-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport