disposable 0.3.2 → 0.4.0

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: d6e1ad3c3bf2e63ee78f3109a5dbdefc4a66e752
4
- data.tar.gz: bdab6ed057dff4c820cb7bbb0e3129c566dbd7b1
3
+ metadata.gz: 95a247503e136210bf70026ebbf2a093de735bcc
4
+ data.tar.gz: d6f1d87dc8408223b808d6fa57c4286673393fb4
5
5
  SHA512:
6
- metadata.gz: 565f5cce96dad1b569ec5747d4cab583de49e8ae93eb01b01ab0620b01f828f21b5c714bea8eef7a657b14c517ff460d99b8fa3fcce2cc53b099c2a6a9392deb
7
- data.tar.gz: 0a89a7b63ff68773aaa44caaa92c1cc8128ef8b75d95b58036989f44f3c37a14c20f0cf3b21ff33c4b6b2417abc5147cb7fa82f6a0cf14e7a61949181dc11835
6
+ metadata.gz: 40be1a5438aa2bf43fb992bb413dc2c503e3ead6f3698e0c91077af418704be339fa9e85d544926241eb2191a0d6226485b60534ec4ef51d2ef7c44b004d8e0b
7
+ data.tar.gz: 4f7e86c71d723b08ff766360816239973955f98220c4ed0b1c93ef10c0372a56279c0a175a373f5ae4dade28c09a758e490713fe4773064bedc394a2f7dc85a9
data/CHANGES.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.4.0
2
+
3
+ * In `#sync {}` with block, `nil` values will now be included in the nested hash, resulting in a hash as follows.
4
+ ```ruby
5
+ twin.sync do |nested_hash|
6
+ nested_hash #=> { uuid: nil, title: "Greatest Hits" }
7
+ ```
8
+ Note that in earlier versions, `nil` values were not included in this hash.
9
+
1
10
  # 0.3.2
2
11
 
3
12
  * Rename `JSONB` to `Property::Hash`.
@@ -90,8 +90,9 @@ class Disposable::Twin
90
90
  def build_nested_hash_representer
91
91
  Sync.hash_representer(self) do |dfn|
92
92
  dfn.merge!(
93
- readable: true, # the nested hash contains all fields.
94
- as: dfn[:private_name] # nested hash keys by model property names.
93
+ readable: true, # the nested hash contains all fields.
94
+ as: dfn[:private_name], # nested hash keys by model property names.
95
+ render_nil: dfn[:collection] ? nil : true,
95
96
  )
96
97
 
97
98
  dfn.merge!(
@@ -1,3 +1,3 @@
1
1
  module Disposable
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -85,7 +85,7 @@ class SaveTest < MiniTest::Spec
85
85
  nested_hash = hash
86
86
  end
87
87
 
88
- nested_hash.must_equal({"name"=>"Live And Dangerous", "songs"=>[{"title"=>"Southbound"}, {"title"=>"The Boys Are Back In Town", "composer"=>{"name"=>"Lynott"}}], "artist"=>{"name"=>"Thin Lizzy"}})
88
+ nested_hash.must_equal({"name"=>"Live And Dangerous", "songs"=>[{"title"=>"Southbound", "composer"=>nil}, {"title"=>"The Boys Are Back In Town", "composer"=>{"name"=>"Lynott"}}], "artist"=>{"name"=>"Thin Lizzy"}})
89
89
 
90
90
  # nothing written to model.
91
91
  album.name.must_equal nil
@@ -189,4 +189,4 @@ end
189
189
  # song.length.must_equal nil
190
190
  # song.id.must_equal "10: 120"
191
191
  # end
192
- # end
192
+ # end
@@ -94,26 +94,54 @@ class TwinSyncTest < MiniTest::Spec
94
94
  album.songs[1].composer.name.must_equal "Lynott"
95
95
  end
96
96
 
97
- # save with block creates nested_hash and doesn't sync.
98
- it do
99
- twin = Twin::Album.new(album)
97
+ # save with block.
98
+ describe "#to_nested_hash" do
99
+ let (:twin) { Twin::Album.new(album) }
100
100
 
101
- # this usually happens in Contract::Validate or in from_* in a representer
102
- fill_out!(twin)
101
+ it "creates nested_hash and doesn't sync" do
102
+ # this usually happens in Contract::Validate or in from_* in a representer
103
+ fill_out!(twin)
104
+
105
+ nested_hash = nil
106
+ twin.sync do |hash|
107
+ nested_hash = hash
108
+ end
109
+
110
+ nested_hash.must_equal({"name"=>"Live And Dangerous", "songs"=>[{"title"=>"Southbound", "composer"=>nil}, {"title"=>"The Boys Are Back In Town", "composer"=>{"name"=>"Lynott"}}], "artist"=>{"name"=>"Thin Lizzy"}})
103
111
 
104
- nested_hash = nil
105
- twin.sync do |hash|
106
- nested_hash = hash
112
+ # nothing written to model.
113
+ album.name.must_equal nil
114
+ album.songs[0].title.must_equal nil
115
+ album.songs[1].title.must_equal nil
116
+ album.songs[1].composer.name.must_equal nil
117
+ album.artist.name.must_equal nil
107
118
  end
108
119
 
109
- nested_hash.must_equal({"name"=>"Live And Dangerous", "songs"=>[{"title"=>"Southbound"}, {"title"=>"The Boys Are Back In Town", "composer"=>{"name"=>"Lynott"}}], "artist"=>{"name"=>"Thin Lizzy"}})
120
+ describe "nil values" do
121
+ it "includes nil values, including nil collections" do
122
+ twin = Twin::Album.new(Model::Album.new(nil,
123
+ nil, # uninitialized nil collection.
124
+ nil)
125
+ )
110
126
 
111
- # nothing written to model.
112
- album.name.must_equal nil
113
- album.songs[0].title.must_equal nil
114
- album.songs[1].title.must_equal nil
115
- album.songs[1].composer.name.must_equal nil
116
- album.artist.name.must_equal nil
127
+ nested_hash = nil
128
+ twin.sync { |hash| nested_hash = hash }
129
+
130
+ nested_hash.must_equal({"name"=>nil, "artist"=>nil})
131
+ end
132
+
133
+ it "includes empty collections" do
134
+ twin = Twin::Album.new(Model::Album.new(nil,
135
+ [], # empty collection.
136
+ nil)
137
+ )
138
+
139
+ nested_hash = nil
140
+ twin.sync { |hash| nested_hash = hash }
141
+
142
+ nested_hash.must_equal({"name"=>nil, "songs"=>[], "artist"=>nil})
143
+ end
144
+ end
117
145
  end
118
146
 
119
147
 
@@ -125,4 +153,4 @@ class TwinSyncTest < MiniTest::Spec
125
153
  twin.artist.name = "Thin Lizzy"
126
154
  end
127
155
  end
128
- end
156
+ end
@@ -21,4 +21,17 @@ class UnnestTest < MiniTest::Spec
21
21
  # also copies :nested.
22
22
  Twin.definitions.get(:email).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:private_name=>:email, :nested=>#<Class:>, :name=>\"email\", :readable=>false, :writeable=>false}>}
23
23
  end
24
+
25
+ it "exposes accessors on top-level twin" do
26
+ twin = Twin.new(OpenStruct.new(content: OpenStruct.new()))
27
+
28
+ twin.email.must_equal nil
29
+ twin.email= 2
30
+ twin.email.model.must_equal 2
31
+
32
+
33
+ twin.id.must_equal nil
34
+ twin.id = 1
35
+ twin.id.must_equal 1
36
+ end
24
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disposable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-05 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber