disposable 0.3.2 → 0.4.0
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 +4 -4
- data/CHANGES.md +9 -0
- data/lib/disposable/twin/sync.rb +3 -2
- data/lib/disposable/version.rb +1 -1
- data/test/twin/save_test.rb +2 -2
- data/test/twin/sync_test.rb +44 -16
- data/test/twin/unnest_test.rb +13 -0
- 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: 95a247503e136210bf70026ebbf2a093de735bcc
|
4
|
+
data.tar.gz: d6f1d87dc8408223b808d6fa57c4286673393fb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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`.
|
data/lib/disposable/twin/sync.rb
CHANGED
@@ -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:
|
94
|
-
as:
|
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!(
|
data/lib/disposable/version.rb
CHANGED
data/test/twin/save_test.rb
CHANGED
@@ -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
|
data/test/twin/sync_test.rb
CHANGED
@@ -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
|
98
|
-
|
99
|
-
twin
|
97
|
+
# save with block.
|
98
|
+
describe "#to_nested_hash" do
|
99
|
+
let (:twin) { Twin::Album.new(album) }
|
100
100
|
|
101
|
-
|
102
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
data/test/twin/unnest_test.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|