yaoc 0.0.7 → 0.0.8

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: 115be6510d49cc1ed39509369d8a13b35574afff
4
- data.tar.gz: 77bc38e239f5ee0dad8a86e4e4e22fa6fa294c46
3
+ metadata.gz: 60a0299fcfe56955d503d23ff8d92b69d2f9aee4
4
+ data.tar.gz: 4946c343a774f4d278298671f781d61ad647fe02
5
5
  SHA512:
6
- metadata.gz: 49986fe1421711286cbc6e67ac58285fb625ad143e5f00bd280807a900884936d43b62fe7e5921cfb40f01603f1393c1c9eefc654b4b5fdd142c3f8b5db3f2b3
7
- data.tar.gz: 41ccc8c0e963f2839e7f610fe313b371e8199fdd9ac521a132ae01bbe6a5ff50336148b4bdb158e3e74d271031f89a2a7db640c93b451d1e318ec4ffd3c8e2ec
6
+ metadata.gz: 27acb99f506e5220e00b16bfd691df573fd1ae1c860c9d0ec9e0a0b229c2a95500884b44e0561b0fcfc61dc2105c608459db1c1d1aafbb0b0bb43b0726e6f37f
7
+ data.tar.gz: 4bcd3ceecda4be8ce9b9c381991c1230249dd0d2c0d912ed91f86d6c356e90174a3e4bbe3294c7710d59a73cc8f0e15f8bf8f97f01eeaf96418ee2fbbc0e7c1f
@@ -28,6 +28,18 @@ module Yaoc
28
28
  super || __getobj__.kind_of?(some_class)
29
29
  end
30
30
 
31
+ def nil?
32
+ __getobj__.nil?
33
+ end
34
+
35
+ def _initialisation_proc_loaded?
36
+ self._initialisation_proc_loaded
37
+ end
38
+
39
+ def _needs_conversion?
40
+ _initialisation_proc_loaded? && ! nil?
41
+ end
42
+
31
43
  end
32
44
  end
33
45
  end
@@ -12,7 +12,8 @@ module Yaoc
12
12
  reverse_converter: nil,
13
13
  object_converter: nil,
14
14
  is_collection: nil,
15
- lazy_loading: nil)
15
+ lazy_loading: nil,
16
+ reverse_lazy_loading: lazy_loading)
16
17
 
17
18
  object_converter = Array(object_converter)
18
19
 
@@ -31,7 +32,7 @@ module Yaoc
31
32
  converter: reverse_converter,
32
33
  object_converter: object_converter.map(&:reverse_converter),
33
34
  is_collection: is_collection,
34
- lazy_loading: lazy_loading
35
+ lazy_loading: reverse_lazy_loading
35
36
  )
36
37
  end
37
38
 
data/lib/yaoc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yaoc
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -25,7 +25,7 @@ describe Yaoc::Helper::ToProcDelegator do
25
25
  expect(subject.first).to eq :some_value
26
26
  end
27
27
 
28
- describe 'kind_of?' do
28
+ describe '#kind_of?' do
29
29
 
30
30
  it 'returns true when class is "real class"' do
31
31
  expect(subject).to be_kind_of Yaoc::Helper::ToProcDelegator
@@ -41,4 +41,15 @@ describe Yaoc::Helper::ToProcDelegator do
41
41
 
42
42
  end
43
43
 
44
+ describe '#nil?' do
45
+ it "returns true when delegate value is nil" do
46
+ subject = Yaoc::Helper::ToProcDelegator.new(->{nil})
47
+ expect(subject).to be_nil
48
+ end
49
+
50
+ it "returns false when delegate value is not nil" do
51
+ expect(subject).not_to be_nil
52
+ end
53
+ end
54
+
44
55
  end
@@ -38,55 +38,40 @@ describe Yaoc::ObjectMapper do
38
38
  describe "#add_mapping" do
39
39
 
40
40
  it "creates a converter" do
41
- expected_params = expected_default_params.merge(
42
- to: :id,
43
- from: :id2,
44
- converter: :some_proc
45
- )
41
+ expected_params = expected_default_params
46
42
 
47
43
  expect(converter_builder).to receive(:rule).with(expected_params)
48
44
 
49
45
  subject.add_mapping do
50
- rule to: :id,
51
- from: :id2,
52
- converter: :some_proc,
53
- reverse_converter: :some_reverse_proc
46
+ rule to: :id
54
47
  end
55
48
 
56
49
  end
57
50
 
58
51
  it "creates a revers converter" do
59
- expected_params = expected_default_params.merge(
60
- to: :id2,
61
- from: :id,
62
- converter: :some_reverse_proc
63
- )
52
+ expected_params = expected_default_params
64
53
 
65
54
  expect(reverse_converter_builder).to receive(:rule).with(expected_params)
66
55
 
67
56
  subject.add_mapping do
68
- rule to: :id,
69
- from: :id2,
70
- converter: :some_proc,
71
- reverse_converter: :some_reverse_proc
57
+ rule to: :id
72
58
  end
73
59
 
74
60
  end
75
61
 
62
+ end
63
+
64
+ describe "#rule" do
65
+
76
66
  it "allows to use another converter as converter" do
77
67
  converter_double = double("converter")
78
68
 
79
69
  expected_params = expected_default_params.merge(
80
- from: :id2,
81
70
  object_converter: [converter_double],
82
- is_collection: false
83
71
  )
84
72
 
85
73
  expected_params_reverse = expected_default_params.merge(
86
- to: :id2,
87
- from: :id,
88
- object_converter: [converter_double],
89
- is_collection: false
74
+ object_converter: [converter_double]
90
75
  )
91
76
 
92
77
 
@@ -99,23 +84,10 @@ describe Yaoc::ObjectMapper do
99
84
 
100
85
  subject.add_mapping do
101
86
  rule to: :id,
102
- from: :id2,
103
- is_collection: false,
104
87
  object_converter: converter_double
105
88
  end
106
89
  end
107
90
 
108
- it "uses defaults" do
109
- expect(converter_builder).to receive(:rule).with(expected_default_params)
110
-
111
- expect(reverse_converter_builder).to receive(:rule).with(expected_default_params)
112
-
113
- subject.add_mapping do
114
- rule to: :id
115
- end
116
-
117
- end
118
-
119
91
  it "accepts a reverse mapping for from and to" do
120
92
  expected_params = expected_default_params.merge(
121
93
  to: :id_r,
@@ -166,6 +138,39 @@ describe Yaoc::ObjectMapper do
166
138
  end
167
139
  end
168
140
 
141
+ it "allows to set lazy_loading" do
142
+ expected_params = expected_default_params.merge(
143
+ lazy_loading: true,
144
+ )
145
+
146
+ expect(converter_builder).to receive(:rule).with(expected_params)
147
+ expect(reverse_converter_builder).to receive(:rule).with(expected_params)
148
+
149
+ subject.add_mapping do
150
+ rule to: :id,
151
+ lazy_loading: true
152
+ end
153
+ end
154
+
155
+ it "allows to set reverse lazy_loading" do
156
+ expected_params = expected_default_params.merge(
157
+ lazy_loading: nil,
158
+ )
159
+
160
+ expected_params_reverse = expected_default_params.merge(
161
+ lazy_loading: true,
162
+ )
163
+
164
+ expect(converter_builder).to receive(:rule).with(expected_params)
165
+ expect(reverse_converter_builder).to receive(:rule).with(expected_params_reverse)
166
+
167
+ subject.add_mapping do
168
+ rule to: :id,
169
+ reverse_lazy_loading: true
170
+ end
171
+ end
172
+
173
+
169
174
  end
170
175
 
171
176
  describe "#load" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter Späth