ree_lib 1.0.110 → 1.0.111
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59f41ff2397eb9507b0e565246430ccde3467b8137bb747991181cecbb99a8d0
|
4
|
+
data.tar.gz: c267d40f7cd30a41ab86f428c0f30eec225a96fc6ed3ca33e9ab58cf130c0529
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04367c6369bd195fa8f2094159f999a1897485632b3e9c86d7e4ed7909513aeef7ea3beba05d544f7660b5bc9a22522f93cd7e3035da6650fbe60ea580d92045
|
7
|
+
data.tar.gz: 305010534eb1ed83b5e7a900b2cd88a9429ce6d1c629527af13dd1ecfcc8951b65a3ca68eb3c74c1a65f1d41e6ebce4cff788b4d5525cc787ab3bf13b0ffdebf
|
data/Gemfile.lock
CHANGED
@@ -9,7 +9,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
9
9
|
] => Array
|
10
10
|
).throws(ReeMapper::TypeError)
|
11
11
|
def serialize(value, role: nil, fields_filters: nil)
|
12
|
-
if !value
|
12
|
+
if !check_value(value)
|
13
13
|
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
|
14
14
|
end
|
15
15
|
|
@@ -40,7 +40,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
40
40
|
] => Array
|
41
41
|
).throws(ReeMapper::TypeError)
|
42
42
|
def cast(value, role: nil, fields_filters: nil)
|
43
|
-
if !value
|
43
|
+
if !check_value(value)
|
44
44
|
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
|
45
45
|
end
|
46
46
|
|
@@ -71,7 +71,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
71
71
|
] => Array
|
72
72
|
).throws(ReeMapper::TypeError)
|
73
73
|
def db_dump(value, role: nil, fields_filters: nil)
|
74
|
-
if !value
|
74
|
+
if !check_value(value)
|
75
75
|
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
|
76
76
|
end
|
77
77
|
|
@@ -102,7 +102,7 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
102
102
|
] => Array
|
103
103
|
).throws(ReeMapper::TypeError)
|
104
104
|
def db_load(value, role: nil, fields_filters: nil)
|
105
|
-
if !value
|
105
|
+
if !check_value(value)
|
106
106
|
raise ReeMapper::TypeError.new("should be an array, got `#{truncate(value.inspect)}`")
|
107
107
|
end
|
108
108
|
|
@@ -124,4 +124,10 @@ class ReeMapper::Array < ReeMapper::AbstractWrapper
|
|
124
124
|
raise e
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def check_value(value)
|
131
|
+
value.is_a?(Array) || value.class.include?(Enumerable)
|
132
|
+
end
|
127
133
|
end
|
@@ -22,7 +22,31 @@ RSpec.describe 'ReeMapper::Array' do
|
|
22
22
|
}
|
23
23
|
}
|
24
24
|
|
25
|
+
class EnumerableArray
|
26
|
+
include Enumerable
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@list = []
|
30
|
+
end
|
31
|
+
|
32
|
+
def each(&proc)
|
33
|
+
@list.each &proc
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(v)
|
37
|
+
@list << v
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
25
41
|
describe '#serialize' do
|
42
|
+
it {
|
43
|
+
ar = EnumerableArray.new
|
44
|
+
ar.add(1)
|
45
|
+
ar.add(2)
|
46
|
+
|
47
|
+
expect(mapper.serialize({ tags: ar, ary_of_ary: [[1]] })).to eq({ tags: [1, 2], ary_of_ary: [[1]] })
|
48
|
+
}
|
49
|
+
|
26
50
|
it {
|
27
51
|
expect(mapper.serialize({ tags: [1, 2], ary_of_ary: [[1]] })).to eq({ tags: [1, 2], ary_of_ary: [[1]] })
|
28
52
|
}
|
@@ -41,6 +65,14 @@ RSpec.describe 'ReeMapper::Array' do
|
|
41
65
|
end
|
42
66
|
|
43
67
|
describe '#cast' do
|
68
|
+
it {
|
69
|
+
ar = EnumerableArray.new
|
70
|
+
ar.add(1)
|
71
|
+
ar.add(2)
|
72
|
+
|
73
|
+
expect(mapper.cast({ 'tags' => ar })).to eq({ tags: [1, 2] })
|
74
|
+
}
|
75
|
+
|
44
76
|
it {
|
45
77
|
expect(mapper.cast({ 'tags' => [1, 2] })).to eq({ tags: [1, 2] })
|
46
78
|
}
|
@@ -51,6 +83,14 @@ RSpec.describe 'ReeMapper::Array' do
|
|
51
83
|
end
|
52
84
|
|
53
85
|
describe '#db_dump' do
|
86
|
+
it {
|
87
|
+
ar = EnumerableArray.new
|
88
|
+
ar.add(1)
|
89
|
+
ar.add(2)
|
90
|
+
|
91
|
+
expect(mapper.db_dump(OpenStruct.new({ tags: ar }))).to eq({ tags: [1, 2] })
|
92
|
+
}
|
93
|
+
|
54
94
|
it {
|
55
95
|
expect(mapper.db_dump(OpenStruct.new({ tags: [1, 2] }))).to eq({ tags: [1, 2] })
|
56
96
|
}
|
@@ -61,6 +101,14 @@ RSpec.describe 'ReeMapper::Array' do
|
|
61
101
|
end
|
62
102
|
|
63
103
|
describe '#db_load' do
|
104
|
+
it {
|
105
|
+
ar = EnumerableArray.new
|
106
|
+
ar.add(1)
|
107
|
+
ar.add(2)
|
108
|
+
|
109
|
+
expect(mapper.db_load({ 'tags' => ar })).to eq({ tags: [1, 2] })
|
110
|
+
}
|
111
|
+
|
64
112
|
it {
|
65
113
|
expect(mapper.db_load({ 'tags' => [1, 2] })).to eq({ tags: [1, 2] })
|
66
114
|
}
|
data/lib/ree_lib/version.rb
CHANGED