sinclair 1.9.0 → 1.11.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/.rubocop.yml +7 -1
- data/README.md +414 -324
- data/config/check_specs.yml +3 -4
- data/config/yardstick.yml +9 -1
- data/lib/sinclair/configurable.rb +2 -0
- data/lib/sinclair/equals_checker.rb +2 -0
- data/lib/sinclair/matchers/add_class_method.rb +26 -36
- data/lib/sinclair/matchers/add_instance_method.rb +59 -59
- data/lib/sinclair/matchers/add_method.rb +33 -35
- data/lib/sinclair/matchers/change_class_method.rb +22 -16
- data/lib/sinclair/matchers/change_instance_method.rb +46 -16
- data/lib/sinclair/matchers.rb +2 -8
- data/lib/sinclair/method_builder/base.rb +17 -2
- data/lib/sinclair/method_builder/call_method_builder.rb +49 -0
- data/lib/sinclair/method_builder.rb +5 -17
- data/lib/sinclair/method_definition/block_definition.rb +2 -0
- data/lib/sinclair/method_definition/call_definition.rb +49 -0
- data/lib/sinclair/method_definition/string_definition.rb +2 -2
- data/lib/sinclair/method_definition.rb +80 -26
- data/lib/sinclair/method_definitions.rb +25 -7
- data/lib/sinclair/options/builder.rb +8 -0
- data/lib/sinclair/options.rb +1 -13
- data/lib/sinclair/version.rb +1 -1
- data/lib/sinclair.rb +149 -62
- data/spec/integration/readme/sinclair/types_of_definition_spec.rb +47 -0
- data/spec/integration/yard/sinclair/add_class_method_spec.rb +51 -0
- data/spec/integration/yard/sinclair/add_method_spec.rb +60 -0
- data/spec/integration/yard/sinclair/eval_and_add_method_spec.rb +26 -0
- data/spec/integration/yard/sinclair/matchers/change_class_method_spec.rb +24 -0
- data/spec/integration/yard/sinclair/matchers/change_instance_method_spec.rb +40 -0
- data/spec/integration/yard/sinclair_spec.rb +0 -83
- data/spec/lib/sinclair/method_builder/base_spec.rb +15 -0
- data/spec/lib/sinclair/method_builder/call_method_builder_spec.rb +76 -0
- data/spec/lib/sinclair/method_builder_spec.rb +63 -20
- data/spec/lib/sinclair/method_definition/call_definition_spec.rb +33 -0
- data/spec/lib/sinclair/method_definition_spec.rb +129 -0
- data/spec/lib/sinclair/method_definitions_spec.rb +79 -1
- data/spec/lib/sinclair/options/builder_spec.rb +13 -0
- data/spec/lib/sinclair/options/class_methods_spec.rb +23 -8
- data/spec/lib/sinclair_spec.rb +6 -160
- data/spec/support/models/dummy_builder.rb +4 -1
- data/spec/support/models/dummy_class_builder.rb +3 -0
- data/spec/support/models/person.rb +1 -1
- data/spec/support/shared_examples/attribute_accessor.rb +103 -0
- data/spec/support/shared_examples/sinclair.rb +112 -0
- metadata +15 -2
@@ -6,7 +6,8 @@ describe Sinclair::MethodDefinitions do
|
|
6
6
|
subject(:definitions) { described_class.new }
|
7
7
|
|
8
8
|
describe '#add' do
|
9
|
-
let(:name)
|
9
|
+
let(:name) { :the_method }
|
10
|
+
let(:klass) { Class.new }
|
10
11
|
|
11
12
|
context 'when passing block' do
|
12
13
|
it 'returns the resulting array' do
|
@@ -41,5 +42,82 @@ describe Sinclair::MethodDefinitions do
|
|
41
42
|
.to be_a(Sinclair::MethodDefinition::StringDefinition)
|
42
43
|
end
|
43
44
|
end
|
45
|
+
|
46
|
+
context 'when there are no options nor block' do
|
47
|
+
let(:type) { :call }
|
48
|
+
let(:arguments) { %i[attr_reader some_attribute other_attribute] }
|
49
|
+
|
50
|
+
it do
|
51
|
+
expect(definitions.add(*arguments, type: type))
|
52
|
+
.to be_a(Array)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'creates a new definition' do
|
56
|
+
expect(definitions.add(*arguments, type: type).last)
|
57
|
+
.to be_a(Sinclair::MethodDefinition)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'creates a new definition of the chosen type' do
|
61
|
+
expect(definitions.add(*arguments, type: type).last)
|
62
|
+
.to be_a(Sinclair::MethodDefinition::CallDefinition)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'initializes it correctly' do
|
66
|
+
expect { klass.module_eval(&definitions.add(*arguments, type: type).last.code_block) }
|
67
|
+
.to add_method(:some_attribute).to(klass)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when a block is given' do
|
72
|
+
let(:type) { :block }
|
73
|
+
let(:method_name) { :the_method }
|
74
|
+
let(:block) { proc { 10 } }
|
75
|
+
|
76
|
+
it do
|
77
|
+
expect(definitions.add(type, method_name, &block))
|
78
|
+
.to be_a(Array)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'creates a new definition' do
|
82
|
+
expect(definitions.add(type, method_name, &block).last)
|
83
|
+
.to be_a(Sinclair::MethodDefinition)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'creates a new definition of the chosen type' do
|
87
|
+
expect(definitions.add(type, method_name, &block).last)
|
88
|
+
.to be_a(Sinclair::MethodDefinition::BlockDefinition)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'initializes it correctly' do
|
92
|
+
expect(definitions.add(method_name, type: type, &block).last.name)
|
93
|
+
.to eq(method_name)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when options are given' do
|
98
|
+
let(:type) { :string }
|
99
|
+
let(:method_name) { :the_method }
|
100
|
+
let(:code) { '10' }
|
101
|
+
|
102
|
+
it do
|
103
|
+
expect(definitions.add(method_name, code, type: type))
|
104
|
+
.to be_a(Array)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'creates a new definition' do
|
108
|
+
expect(definitions.add(method_name, code, type: type).last)
|
109
|
+
.to be_a(Sinclair::MethodDefinition)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'creates a new definition of the chosen type' do
|
113
|
+
expect(definitions.add(method_name, code, type: type).last)
|
114
|
+
.to be_a(Sinclair::MethodDefinition::StringDefinition)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'initializes it correctly' do
|
118
|
+
expect(definitions.add(method_name, code, type: type).last.name)
|
119
|
+
.to eq(method_name)
|
120
|
+
end
|
121
|
+
end
|
44
122
|
end
|
45
123
|
end
|
@@ -40,6 +40,19 @@ describe Sinclair::Options::Builder do
|
|
40
40
|
.not_to change { Sinclair::Options.invalid_options_in(test_keys) }
|
41
41
|
end
|
42
42
|
|
43
|
+
context 'when the object is compared with others' do
|
44
|
+
before { klass.skip_validation }
|
45
|
+
|
46
|
+
let(:options1) { klass.new(timeout: 10) }
|
47
|
+
let(:options2) { klass.new(timeout: 15) }
|
48
|
+
|
49
|
+
it 'adds the field to the equals check' do
|
50
|
+
expect { builder.build }
|
51
|
+
.to change { options1 == options2 }
|
52
|
+
.from(true).to(false)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
43
56
|
context 'when when calling method after building' do
|
44
57
|
before { builder.build }
|
45
58
|
|
@@ -27,11 +27,26 @@ describe Sinclair::Options::ClassMethods do
|
|
27
27
|
.to([:invalid])
|
28
28
|
end
|
29
29
|
|
30
|
+
context 'when the added fild makes an object different' do
|
31
|
+
let(:options1_hash) { { timeout: 10 } }
|
32
|
+
let(:options2_hash) { { timeout: 11 } }
|
33
|
+
|
34
|
+
before do
|
35
|
+
klass.skip_validation
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'adds the field to == check' do
|
39
|
+
expect { klass.send(:with_options, :timeout) }
|
40
|
+
.to change { klass.new(options1_hash) == klass.new(options2_hash) }
|
41
|
+
.from(true).to(false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
30
45
|
it do
|
31
46
|
expect { klass.send(:with_options, :timeout, 'retries') }
|
32
47
|
.not_to change {
|
33
|
-
|
34
|
-
|
48
|
+
Sinclair::Options.invalid_options_in(%i[timeout retries invalid])
|
49
|
+
}
|
35
50
|
end
|
36
51
|
|
37
52
|
context 'when when calling method after building' do
|
@@ -46,8 +61,8 @@ describe Sinclair::Options::ClassMethods do
|
|
46
61
|
it do
|
47
62
|
expect { klass.send(:with_options, :timeout, :retries) }
|
48
63
|
.not_to change {
|
49
|
-
|
50
|
-
|
64
|
+
klass.invalid_options_in(%i[timeout retries invalid])
|
65
|
+
}
|
51
66
|
end
|
52
67
|
end
|
53
68
|
end
|
@@ -90,16 +105,16 @@ describe Sinclair::Options::ClassMethods do
|
|
90
105
|
it do
|
91
106
|
expect { klass.send(:with_options, 'protocol', port: 443) }
|
92
107
|
.to change {
|
93
|
-
|
94
|
-
|
108
|
+
klass.invalid_options_in(test_keys)
|
109
|
+
}.from(%i[protocol port invalid])
|
95
110
|
.to([:invalid])
|
96
111
|
end
|
97
112
|
|
98
113
|
it do
|
99
114
|
expect { klass.send(:with_options, 'protocol', port: 443) }
|
100
115
|
.not_to change {
|
101
|
-
|
102
|
-
|
116
|
+
super_class.invalid_options_in(%i[protocol port])
|
117
|
+
}
|
103
118
|
end
|
104
119
|
|
105
120
|
context 'when overriding a method' do
|
data/spec/lib/sinclair_spec.rb
CHANGED
@@ -11,86 +11,15 @@ describe Sinclair do
|
|
11
11
|
let(:builder_class) { described_class }
|
12
12
|
|
13
13
|
describe '#add_method' do
|
14
|
-
|
15
|
-
let(:builder_class) { described_class::DummyBuilder }
|
14
|
+
let(:object) { instance }
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
builder.build
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when describing a method with block' do
|
23
|
-
it 'creates a method with the block' do
|
24
|
-
expect(instance.blocked).to eq(1)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when describing a method with string' do
|
29
|
-
it 'creates a method using the string definition' do
|
30
|
-
expect(instance.defined).to eq(1)
|
31
|
-
expect(instance.defined).to eq(2)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when passing options' do
|
36
|
-
let(:options) { { increment: 2 } }
|
37
|
-
|
38
|
-
it 'parses the options' do
|
39
|
-
expect(instance.defined).to eq(2)
|
40
|
-
expect(instance.defined).to eq(4)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'when using the builder without extending' do
|
46
|
-
context 'when declaring a method with a block' do
|
47
|
-
before do
|
48
|
-
builder.add_method(:blocked) { 1 }
|
49
|
-
builder.add_method(:blocked) { 2 }
|
50
|
-
builder.build
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'respect the order of method addtion' do
|
54
|
-
expect(instance.blocked).to eq(2)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'when declaring a method string' do
|
59
|
-
before do
|
60
|
-
builder.add_method(:string, '1')
|
61
|
-
builder.add_method(:string, '2')
|
62
|
-
builder.build
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'respect the order of method addtion' do
|
66
|
-
expect(instance.string).to eq(2)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when declaring block and string' do
|
71
|
-
before do
|
72
|
-
builder.add_method(:value) { 1 }
|
73
|
-
builder.add_method(:value, '2')
|
74
|
-
builder.build
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'respect the order of method addtion' do
|
78
|
-
expect(instance.value).to eq(2)
|
79
|
-
end
|
80
|
-
end
|
16
|
+
it_behaves_like 'A sinclair builder', :instance
|
17
|
+
end
|
81
18
|
|
82
|
-
|
83
|
-
|
84
|
-
builder.add_method(:value, '1')
|
85
|
-
builder.add_method(:value) { 2 }
|
86
|
-
builder.build
|
87
|
-
end
|
19
|
+
describe '#add_class_method' do
|
20
|
+
let(:object) { dummy_class }
|
88
21
|
|
89
|
-
|
90
|
-
expect(instance.value).to eq(2)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
22
|
+
it_behaves_like 'A sinclair builder', :class
|
94
23
|
end
|
95
24
|
|
96
25
|
describe '#eval_and_add_method' do
|
@@ -149,87 +78,4 @@ describe Sinclair do
|
|
149
78
|
end
|
150
79
|
end
|
151
80
|
end
|
152
|
-
|
153
|
-
describe '#add_class_method' do
|
154
|
-
context 'when extending the class' do
|
155
|
-
let(:builder_class) { described_class::DummyClassBuilder }
|
156
|
-
|
157
|
-
before do
|
158
|
-
builder.init
|
159
|
-
builder.build
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'when describing a method with block' do
|
163
|
-
it 'creates a method with the block' do
|
164
|
-
expect(dummy_class.blocked).to eq(1)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'when describing a method with string' do
|
169
|
-
it 'creates a method using the string definition' do
|
170
|
-
expect(dummy_class.defined).to eq(1)
|
171
|
-
expect(dummy_class.defined).to eq(2)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context 'when passing options' do
|
176
|
-
let(:options) { { increment: 2 } }
|
177
|
-
|
178
|
-
it 'parses the options' do
|
179
|
-
expect(dummy_class.defined).to eq(2)
|
180
|
-
expect(dummy_class.defined).to eq(4)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context 'when using the builder without extending' do
|
186
|
-
context 'when declaring a method with a block' do
|
187
|
-
before do
|
188
|
-
builder.add_class_method(:blocked) { 1 }
|
189
|
-
builder.add_class_method(:blocked) { 2 }
|
190
|
-
builder.build
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'respect the order of method addtion' do
|
194
|
-
expect(dummy_class.blocked).to eq(2)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'when declaring a method string' do
|
199
|
-
before do
|
200
|
-
builder.add_class_method(:string, '1')
|
201
|
-
builder.add_class_method(:string, '2')
|
202
|
-
builder.build
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'respect the order of method addtion' do
|
206
|
-
expect(dummy_class.string).to eq(2)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context 'when declaring block and string' do
|
211
|
-
before do
|
212
|
-
builder.add_class_method(:value) { 1 }
|
213
|
-
builder.add_class_method(:value, '2')
|
214
|
-
builder.build
|
215
|
-
end
|
216
|
-
|
217
|
-
it 'respect the order of method addtion' do
|
218
|
-
expect(dummy_class.value).to eq(2)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
context 'when declaring string and block' do
|
223
|
-
before do
|
224
|
-
builder.add_class_method(:value, '1')
|
225
|
-
builder.add_class_method(:value) { 2 }
|
226
|
-
builder.build
|
227
|
-
end
|
228
|
-
|
229
|
-
it 'respect the order of method addtion' do
|
230
|
-
expect(dummy_class.value).to eq(2)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
81
|
end
|
@@ -5,7 +5,10 @@ class Sinclair
|
|
5
5
|
def init
|
6
6
|
add_method(:blocked) { 1 }
|
7
7
|
add_method(:defined, "@value = value + #{options_object&.increment || 1}")
|
8
|
-
add_method(:value,
|
8
|
+
add_method(:value, cached: true) { 0 }
|
9
|
+
add_method(:type_block, type: :block) { 3 }
|
10
|
+
add_method(:type_string, '10', type: :string)
|
11
|
+
add_method(:attr_accessor, :some_attribute, type: :call)
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
@@ -6,6 +6,9 @@ class Sinclair
|
|
6
6
|
add_class_method(:blocked) { 1 }
|
7
7
|
add_class_method(:defined, "@value = value + #{options_object&.increment || 1}")
|
8
8
|
add_class_method(:value, '@value ||= 0')
|
9
|
+
add_class_method(:type_block, type: :block) { 3 }
|
10
|
+
add_class_method(:type_string, '10', type: :string)
|
11
|
+
add_class_method(:attr_accessor, :some_attribute, type: :call)
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples 'a method builder that adds attribute reader' do
|
4
|
+
let(:klass) { Class.new }
|
5
|
+
let(:instance) { klass.new }
|
6
|
+
let(:value) { Random.rand(10..20) }
|
7
|
+
let(:method_name) { :the_method }
|
8
|
+
let(:attributes) { [method_name] }
|
9
|
+
|
10
|
+
context 'when type is instance' do
|
11
|
+
let(:type) { Sinclair::MethodBuilder::INSTANCE_METHOD }
|
12
|
+
|
13
|
+
it do
|
14
|
+
expect { builder.build }
|
15
|
+
.to add_method(method_name).to(instance)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when the method is built' do
|
19
|
+
before do
|
20
|
+
builder.build
|
21
|
+
instance.instance_variable_set("@#{method_name}", value)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the value of the instance variable' do
|
25
|
+
expect(instance.the_method).to eq(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when type is class' do
|
31
|
+
let(:type) { Sinclair::MethodBuilder::CLASS_METHOD }
|
32
|
+
|
33
|
+
it do
|
34
|
+
expect { builder.build }
|
35
|
+
.to add_class_method(method_name).to(klass)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when the method is built' do
|
39
|
+
before do
|
40
|
+
builder.build
|
41
|
+
klass.instance_variable_set("@#{method_name}", value)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns the value of the instance variable' do
|
45
|
+
expect(klass.the_method).to eq(value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
shared_examples 'a method builder that adds attribute writer' do
|
52
|
+
let(:klass) { Class.new }
|
53
|
+
let(:instance) { klass.new }
|
54
|
+
let(:value) { Random.rand }
|
55
|
+
let(:method_name) { :the_method }
|
56
|
+
let(:attributes) { [method_name] }
|
57
|
+
|
58
|
+
context 'when type is instance' do
|
59
|
+
let(:type) { Sinclair::MethodBuilder::INSTANCE_METHOD }
|
60
|
+
|
61
|
+
it do
|
62
|
+
expect { builder.build }
|
63
|
+
.to add_method("#{method_name}=").to(instance)
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when the method is built' do
|
67
|
+
let(:value) { Random.rand(10..20) }
|
68
|
+
|
69
|
+
before do
|
70
|
+
builder.build
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'change the instance variable' do
|
74
|
+
expect { instance.the_method = value }
|
75
|
+
.to change { instance.instance_variable_get("@#{method_name}") }
|
76
|
+
.from(nil).to(value)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when type is class' do
|
82
|
+
let(:type) { Sinclair::MethodBuilder::CLASS_METHOD }
|
83
|
+
|
84
|
+
it do
|
85
|
+
expect { builder.build }
|
86
|
+
.to add_class_method("#{method_name}=").to(klass)
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when the method is built' do
|
90
|
+
let(:value) { Random.rand(10..20) }
|
91
|
+
|
92
|
+
before do
|
93
|
+
builder.build
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'change the instance variable' do
|
97
|
+
expect { klass.the_method = value }
|
98
|
+
.to change { klass.instance_variable_get("@#{method_name}") }
|
99
|
+
.from(nil).to(value)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples 'A sinclair builder' do |type|
|
4
|
+
let(:method_name) do
|
5
|
+
type == :instance ? :add_method : :add_class_method
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'when extending the builder' do
|
9
|
+
let(:builder_class) do
|
10
|
+
type == :instance ? described_class::DummyBuilder : described_class::DummyClassBuilder
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
builder.init
|
15
|
+
builder.build
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when describing a method with block' do
|
19
|
+
it 'creates a method with the block' do
|
20
|
+
expect(object.blocked).to eq(1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when describing a method with string' do
|
25
|
+
it 'creates a method using the string definition' do
|
26
|
+
expect(object.defined).to eq(1)
|
27
|
+
expect(object.defined).to eq(2)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when describing a method using a block specific type' do
|
32
|
+
it 'creates a method with the block' do
|
33
|
+
expect(object.type_block).to eq(3)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when describing a method using a string specific type' do
|
38
|
+
it 'creates a method with the string' do
|
39
|
+
expect(object.type_string).to eq(10)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when describing a method using a call specific type for attr_acessor' do
|
44
|
+
let(:value) { Random.rand }
|
45
|
+
|
46
|
+
it 'creates acessors' do
|
47
|
+
expect { object.some_attribute = value }
|
48
|
+
.to change(object, :some_attribute)
|
49
|
+
.from(nil).to(value)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when passing options' do
|
54
|
+
let(:options) { { increment: 2 } }
|
55
|
+
|
56
|
+
it 'parses the options' do
|
57
|
+
expect(object.defined).to eq(2)
|
58
|
+
expect(object.defined).to eq(4)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when adding methods to a regular builder' do
|
64
|
+
context 'when declaring a method with a block' do
|
65
|
+
before do
|
66
|
+
builder.public_send(method_name, :blocked) { 1 }
|
67
|
+
builder.public_send(method_name, :blocked) { 2 }
|
68
|
+
builder.build
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'respect the order of method addtion' do
|
72
|
+
expect(object.blocked).to eq(2)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when declaring a method string' do
|
77
|
+
before do
|
78
|
+
builder.public_send(method_name, :string, '1')
|
79
|
+
builder.public_send(method_name, :string, '2')
|
80
|
+
builder.build
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'respect the order of method addtion' do
|
84
|
+
expect(object.string).to eq(2)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when declaring block and string' do
|
89
|
+
before do
|
90
|
+
builder.public_send(method_name, :value) { 1 }
|
91
|
+
builder.public_send(method_name, :value, '2')
|
92
|
+
builder.build
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'respect the order of method addtion' do
|
96
|
+
expect(object.value).to eq(2)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when declaring string and block' do
|
101
|
+
before do
|
102
|
+
builder.public_send(method_name, :value, '1')
|
103
|
+
builder.public_send(method_name, :value) { 2 }
|
104
|
+
builder.build
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'respect the order of method addtion' do
|
108
|
+
expect(object.value).to eq(2)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinclair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarthJee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -302,10 +302,12 @@ files:
|
|
302
302
|
- lib/sinclair/method_builder.rb
|
303
303
|
- lib/sinclair/method_builder/base.rb
|
304
304
|
- lib/sinclair/method_builder/block_method_builder.rb
|
305
|
+
- lib/sinclair/method_builder/call_method_builder.rb
|
305
306
|
- lib/sinclair/method_builder/string_method_builder.rb
|
306
307
|
- lib/sinclair/method_definition.rb
|
307
308
|
- lib/sinclair/method_definition/block_definition.rb
|
308
309
|
- lib/sinclair/method_definition/block_helper.rb
|
310
|
+
- lib/sinclair/method_definition/call_definition.rb
|
309
311
|
- lib/sinclair/method_definition/string_definition.rb
|
310
312
|
- lib/sinclair/method_definitions.rb
|
311
313
|
- lib/sinclair/options.rb
|
@@ -322,8 +324,11 @@ files:
|
|
322
324
|
- spec/integration/readme/sinclair/env_settable_spec.rb
|
323
325
|
- spec/integration/readme/sinclair/matchers_spec.rb
|
324
326
|
- spec/integration/readme/sinclair/options_spec.rb
|
327
|
+
- spec/integration/readme/sinclair/types_of_definition_spec.rb
|
325
328
|
- spec/integration/readme/sinclair_spec.rb
|
326
329
|
- spec/integration/yard/my_builder_spec.rb
|
330
|
+
- spec/integration/yard/sinclair/add_class_method_spec.rb
|
331
|
+
- spec/integration/yard/sinclair/add_method_spec.rb
|
327
332
|
- spec/integration/yard/sinclair/comparable_spec.rb
|
328
333
|
- spec/integration/yard/sinclair/config_builder_spec.rb
|
329
334
|
- spec/integration/yard/sinclair/config_class_spec.rb
|
@@ -332,11 +337,14 @@ files:
|
|
332
337
|
- spec/integration/yard/sinclair/configurable_spec.rb
|
333
338
|
- spec/integration/yard/sinclair/env_settable_spec.rb
|
334
339
|
- spec/integration/yard/sinclair/equals_checker_spec.rb
|
340
|
+
- spec/integration/yard/sinclair/eval_and_add_method_spec.rb
|
335
341
|
- spec/integration/yard/sinclair/input_hash_spec.rb
|
336
342
|
- spec/integration/yard/sinclair/matchers/add_class_method_spec.rb
|
337
343
|
- spec/integration/yard/sinclair/matchers/add_class_method_to_spec.rb
|
338
344
|
- spec/integration/yard/sinclair/matchers/add_instance_method_spec.rb
|
339
345
|
- spec/integration/yard/sinclair/matchers/add_instance_method_to_spec.rb
|
346
|
+
- spec/integration/yard/sinclair/matchers/change_class_method_spec.rb
|
347
|
+
- spec/integration/yard/sinclair/matchers/change_instance_method_spec.rb
|
340
348
|
- spec/integration/yard/sinclair/options_parser_spec.rb
|
341
349
|
- spec/integration/yard/sinclair/options_spec.rb
|
342
350
|
- spec/integration/yard/sinclair_spec.rb
|
@@ -361,11 +369,14 @@ files:
|
|
361
369
|
- spec/lib/sinclair/matchers/change_instance_method_on_spec.rb
|
362
370
|
- spec/lib/sinclair/matchers/change_instance_method_spec.rb
|
363
371
|
- spec/lib/sinclair/matchers_spec.rb
|
372
|
+
- spec/lib/sinclair/method_builder/base_spec.rb
|
364
373
|
- spec/lib/sinclair/method_builder/block_method_builder_spec.rb
|
374
|
+
- spec/lib/sinclair/method_builder/call_method_builder_spec.rb
|
365
375
|
- spec/lib/sinclair/method_builder/string_method_builder_spec.rb
|
366
376
|
- spec/lib/sinclair/method_builder_spec.rb
|
367
377
|
- spec/lib/sinclair/method_definition/block_definition_spec.rb
|
368
378
|
- spec/lib/sinclair/method_definition/block_helper_spec.rb
|
379
|
+
- spec/lib/sinclair/method_definition/call_definition_spec.rb
|
369
380
|
- spec/lib/sinclair/method_definition/string_definition_spec.rb
|
370
381
|
- spec/lib/sinclair/method_definition_spec.rb
|
371
382
|
- spec/lib/sinclair/method_definitions_spec.rb
|
@@ -413,11 +424,13 @@ files:
|
|
413
424
|
- spec/support/models/service_client.rb
|
414
425
|
- spec/support/models/validator_builder.rb
|
415
426
|
- spec/support/sample_model.rb
|
427
|
+
- spec/support/shared_examples/attribute_accessor.rb
|
416
428
|
- spec/support/shared_examples/class_method_definition.rb
|
417
429
|
- spec/support/shared_examples/config.rb
|
418
430
|
- spec/support/shared_examples/config_factory.rb
|
419
431
|
- spec/support/shared_examples/env_settable.rb
|
420
432
|
- spec/support/shared_examples/instance_method_definition.rb
|
433
|
+
- spec/support/shared_examples/sinclair.rb
|
421
434
|
homepage: https://github.com/darthjee/sinclair
|
422
435
|
licenses: []
|
423
436
|
metadata: {}
|