client-data-adapter 0.1.2 → 0.1.3
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/CHANGELOG.md +9 -0
- data/demo/book.rb +10 -2
- data/lib/client-data-adapter/version.rb +1 -1
- data/lib/client-data-adapter/wrapper.rb +6 -2
- data/spec/link_spec.rb +20 -0
- data/spec/version_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b739882e796050a2b3c2c22456478422524bc8b8756c01db2cdb858baaf5995f
|
|
4
|
+
data.tar.gz: 64bb8b43f1f2049cffdcf615bc59dcc0b7ba9e921c65308a17f66144e8801b4b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 49e171fa93f878013e355608484b4163dff9a09794b9bfacf363670b660c2477fd79c32f2e8fa9a0cee861244e38fb140c25d3889e4daa3ea6144fdb56e28ec1
|
|
7
|
+
data.tar.gz: c98d72212d6d3f09a0127cdb81e1aa96290c486ced1eb6b3f6234be7fb1ee3fe535a7c14db96c7a86db81915989384914491b1e6a4e42a1fb094091145589e3d
|
data/CHANGELOG.md
ADDED
data/demo/book.rb
CHANGED
|
@@ -8,8 +8,8 @@ class Book
|
|
|
8
8
|
|
|
9
9
|
define_adapter do
|
|
10
10
|
|
|
11
|
-
link_one :book_shelf
|
|
12
|
-
link_many :categories
|
|
11
|
+
link_one :book_shelf, :empty_book_shelf
|
|
12
|
+
link_many :categories, :empty_categories
|
|
13
13
|
|
|
14
14
|
adapter do
|
|
15
15
|
{
|
|
@@ -78,4 +78,12 @@ class Book
|
|
|
78
78
|
[Category.new(id: 1, cat: 'one'), Category.new(id: 2, cat: 'two')]
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
def empty_book_shelf
|
|
82
|
+
nil
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def empty_categories
|
|
86
|
+
nil
|
|
87
|
+
end
|
|
88
|
+
|
|
81
89
|
end
|
|
@@ -53,7 +53,11 @@ module ClientDataAdapter
|
|
|
53
53
|
def self.link_one(*associations)
|
|
54
54
|
associations.each do |assoc|
|
|
55
55
|
with(assoc) do |*args|
|
|
56
|
-
public_send(assoc.to_sym)
|
|
56
|
+
obj = public_send(assoc.to_sym)
|
|
57
|
+
|
|
58
|
+
if obj.respond_to?(:adapter)
|
|
59
|
+
obj.adapter(*args)
|
|
60
|
+
end
|
|
57
61
|
end
|
|
58
62
|
end
|
|
59
63
|
end
|
|
@@ -74,7 +78,7 @@ module ClientDataAdapter
|
|
|
74
78
|
def self.link_many(*associations)
|
|
75
79
|
associations.each do |assoc|
|
|
76
80
|
with(assoc) do |*args|
|
|
77
|
-
public_send(assoc.to_sym).map do |elem|
|
|
81
|
+
(public_send(assoc.to_sym) || []).map do |elem|
|
|
78
82
|
elem.adapter(*args)
|
|
79
83
|
end
|
|
80
84
|
end
|
data/spec/link_spec.rb
CHANGED
|
@@ -101,4 +101,24 @@ RSpec.describe ClientDataAdapter do
|
|
|
101
101
|
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
+
it "if link one's target is nil, return nil" do
|
|
105
|
+
expect(@book.adapter_wrapper.empty_book_shelf).to eq(nil)
|
|
106
|
+
expect(@book.adapter(:empty_book_shelf))
|
|
107
|
+
.to eq(
|
|
108
|
+
id: @book.id,
|
|
109
|
+
title: @book.title,
|
|
110
|
+
empty_book_shelf: nil,
|
|
111
|
+
)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "if link many's target is nil, return []" do
|
|
115
|
+
expect(@book.adapter_wrapper.empty_categories).to eq([])
|
|
116
|
+
expect(@book.adapter(:empty_categories))
|
|
117
|
+
.to eq(
|
|
118
|
+
id: @book.id,
|
|
119
|
+
title: @book.title,
|
|
120
|
+
empty_categories: [],
|
|
121
|
+
)
|
|
122
|
+
end
|
|
123
|
+
|
|
104
124
|
end
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: client-data-adapter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- shadow
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-03-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: For unify data formats to transfer to clients.
|
|
14
14
|
email:
|
|
@@ -20,6 +20,7 @@ files:
|
|
|
20
20
|
- ".gitignore"
|
|
21
21
|
- ".rspec"
|
|
22
22
|
- ".travis.yml"
|
|
23
|
+
- CHANGELOG.md
|
|
23
24
|
- Gemfile
|
|
24
25
|
- LICENSE
|
|
25
26
|
- README.md
|