json_array_serializer 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e7a4e281f8c0cd7f9375760778ee6f8e6caaf76
4
- data.tar.gz: 7db5e8490e317f3a57c95c8b787aa6d31aa07cdf
3
+ metadata.gz: b807cc16ab752f8e582a10fe768148aa866aaa2d
4
+ data.tar.gz: 92a2d1de692dc88602fbb4ac635f4e71bbf58146
5
5
  SHA512:
6
- metadata.gz: fa1c7b226056e7812621d8becbab7dc302117f054cef04ed77ce3cce04b2264b3a011169c135cfb963d6cb112241313925b9b5a5d8406a003c34504b82cc15f4
7
- data.tar.gz: 10c856a3be1bc47e44d4359cb25584f6037643b94395b578887fb72143419e531bb124d9c645036f68b47789e65e02e3a61602856abcf49da08133483ab5ef32
6
+ metadata.gz: 8e4ba0eb0f88360647930a607f93a580f9e783e4ff0b32d9e3f22a5b618af903a6e8d43fc0342fd4a7e1cd2d4f88f219e697c220d7c887659609bfafb5b9324d
7
+ data.tar.gz: c564a30d3fd9d904c9a05757d3a54a8a17cbf7c1b301a106332e2c077b9a7f738bca0255b1d4d169d507aecd6679035814e43e859a5ff072cfbff065b889f7f6
@@ -1,3 +1,3 @@
1
1
  class JSONArraySerializer < Array
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -69,13 +69,19 @@ class JSONArraySerializer
69
69
  # and dumps them either a array of JSON or JSON itself for the database.
70
70
  #
71
71
  def dump(data)
72
- return (@allow_nil ? nil : []) if data.nil?
73
-
74
72
  case @column_type
75
73
  when :array
76
- data.to_a.map { |e| JSON.dump(e.to_h) }
74
+ if data.nil?
75
+ @allow_nil ? nil : []
76
+ else
77
+ data.to_a.map { |e| JSON.dump(e.to_h) }
78
+ end
77
79
  when :string, :text
78
- JSON.dump(data.to_a.map { |e| e.to_h })
80
+ if data.nil?
81
+ @allow_nil ? nil : '[]'
82
+ else
83
+ JSON.dump(data.to_a.map { |e| e.to_h })
84
+ end
79
85
  end
80
86
  end
81
87
  end
@@ -225,17 +225,20 @@ describe JSONArraySerializer do
225
225
  end
226
226
 
227
227
  context 'with allow_nil set to false' do
228
- let(:serializer) { JSONArraySerializer.new(allow_nil: false) }
228
+ let(:text_serializer) { JSONArraySerializer.new(allow_nil: false) }
229
+ let(:array_serializer) { JSONArraySerializer.new(allow_nil: false, column_type: :array) }
229
230
 
230
231
  describe '#load' do
231
232
  it 'loads nil as []' do
232
- expect(serializer.load(nil)).to eq([])
233
+ expect(text_serializer.load(nil)).to eq([])
234
+ expect(array_serializer.load(nil)).to eq([])
233
235
  end
234
236
  end
235
237
 
236
238
  describe '#dump' do
237
239
  it 'dumps nil as []' do
238
- expect(['[]', []]).to include(serializer.dump(nil))
240
+ expect(text_serializer.dump(nil)).to eq('[]')
241
+ expect(array_serializer.dump(nil)).to eq([])
239
242
  end
240
243
  end
241
244
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_array_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Lilienthal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler