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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54bb7885e36c6e30b764989256fa62027aec133929e50586020d609fbce300b8
4
- data.tar.gz: af9a20df7ad48c3e49289dc806aa2d05fbe88d11bbe4b007b166e88afa22d8f6
3
+ metadata.gz: b739882e796050a2b3c2c22456478422524bc8b8756c01db2cdb858baaf5995f
4
+ data.tar.gz: 64bb8b43f1f2049cffdcf615bc59dcc0b7ba9e921c65308a17f66144e8801b4b
5
5
  SHA512:
6
- metadata.gz: 521b80d2ee6b8d2e07c3999af388048bc7ba76a5391209b7f7ef039c009ade37372ab0d65ef33ba96d3a85dae2d78a5cb9fdcfca4d9322333103f35be08c2465
7
- data.tar.gz: 3e520deb030e51ab487ed9499d7b21a3a23a24b5aae3433d9598d20cee0d55e411debd8a83c1dd0863090d9ac632464764c188c0ffc599be391043db2fe9bafc
6
+ metadata.gz: 49e171fa93f878013e355608484b4163dff9a09794b9bfacf363670b660c2477fd79c32f2e8fa9a0cee861244e38fb140c25d3889e4daa3ea6144fdb56e28ec1
7
+ data.tar.gz: c98d72212d6d3f09a0127cdb81e1aa96290c486ced1eb6b3f6234be7fb1ee3fe535a7c14db96c7a86db81915989384914491b1e6a4e42a1fb094091145589e3d
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## v0.1.3 (20200310)
4
+
5
+ Change
6
+
7
+ - `link_one` if linked target not exist, return `nil`
8
+ - `link_many` if linked target not exist, return `[]`
9
+
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ClientDataAdapter
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  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).adapter(*args)
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
@@ -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
@@ -5,7 +5,7 @@ RSpec.describe ClientDataAdapter do
5
5
  it "should return the version" do
6
6
 
7
7
  expect(ClientDataAdapter::VERSION)
8
- .to eq('0.1.2')
8
+ .to eq('0.1.3')
9
9
 
10
10
  end
11
11
 
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.2
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: 2019-12-16 00:00:00.000000000 Z
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