sinclair 1.10.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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/README.md +414 -324
  4. data/config/check_specs.yml +3 -4
  5. data/config/yardstick.yml +2 -0
  6. data/lib/sinclair/matchers/add_class_method.rb +0 -1
  7. data/lib/sinclair/method_builder/base.rb +17 -2
  8. data/lib/sinclair/method_builder/call_method_builder.rb +21 -21
  9. data/lib/sinclair/method_builder.rb +5 -20
  10. data/lib/sinclair/method_definition/block_definition.rb +2 -0
  11. data/lib/sinclair/method_definition/call_definition.rb +15 -18
  12. data/lib/sinclair/method_definition/string_definition.rb +2 -0
  13. data/lib/sinclair/method_definition.rb +41 -3
  14. data/lib/sinclair/method_definitions.rb +20 -22
  15. data/lib/sinclair/version.rb +1 -1
  16. data/lib/sinclair.rb +149 -62
  17. data/spec/integration/readme/sinclair/types_of_definition_spec.rb +47 -0
  18. data/spec/integration/yard/sinclair/add_class_method_spec.rb +51 -0
  19. data/spec/integration/yard/sinclair/add_method_spec.rb +60 -0
  20. data/spec/integration/yard/sinclair/eval_and_add_method_spec.rb +26 -0
  21. data/spec/integration/yard/sinclair_spec.rb +0 -83
  22. data/spec/lib/sinclair/method_builder/base_spec.rb +15 -0
  23. data/spec/lib/sinclair/method_definition/call_definition_spec.rb +14 -17
  24. data/spec/lib/sinclair/method_definition_spec.rb +67 -2
  25. data/spec/lib/sinclair/method_definitions_spec.rb +15 -16
  26. data/spec/lib/sinclair_spec.rb +6 -160
  27. data/spec/support/models/dummy_builder.rb +4 -1
  28. data/spec/support/models/dummy_class_builder.rb +3 -0
  29. data/spec/support/models/person.rb +1 -1
  30. data/spec/support/shared_examples/sinclair.rb +112 -0
  31. metadata +8 -2
@@ -11,86 +11,15 @@ describe Sinclair do
11
11
  let(:builder_class) { described_class }
12
12
 
13
13
  describe '#add_method' do
14
- context 'when extending the class' do
15
- let(:builder_class) { described_class::DummyBuilder }
14
+ let(:object) { instance }
16
15
 
17
- before do
18
- builder.init
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
- context 'when declaring string and block' do
83
- before do
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
- it 'respect the order of method addtion' do
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, '@value ||= 0')
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Person
4
- attr_reader :first_name, :last_name
4
+ attr_accessor :first_name, :last_name
5
5
 
6
6
  def initialize(first_name, last_name)
7
7
  @first_name = first_name
@@ -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.10.0
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-02-23 00:00:00.000000000 Z
11
+ date: 2023-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -324,8 +324,11 @@ files:
324
324
  - spec/integration/readme/sinclair/env_settable_spec.rb
325
325
  - spec/integration/readme/sinclair/matchers_spec.rb
326
326
  - spec/integration/readme/sinclair/options_spec.rb
327
+ - spec/integration/readme/sinclair/types_of_definition_spec.rb
327
328
  - spec/integration/readme/sinclair_spec.rb
328
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
329
332
  - spec/integration/yard/sinclair/comparable_spec.rb
330
333
  - spec/integration/yard/sinclair/config_builder_spec.rb
331
334
  - spec/integration/yard/sinclair/config_class_spec.rb
@@ -334,6 +337,7 @@ files:
334
337
  - spec/integration/yard/sinclair/configurable_spec.rb
335
338
  - spec/integration/yard/sinclair/env_settable_spec.rb
336
339
  - spec/integration/yard/sinclair/equals_checker_spec.rb
340
+ - spec/integration/yard/sinclair/eval_and_add_method_spec.rb
337
341
  - spec/integration/yard/sinclair/input_hash_spec.rb
338
342
  - spec/integration/yard/sinclair/matchers/add_class_method_spec.rb
339
343
  - spec/integration/yard/sinclair/matchers/add_class_method_to_spec.rb
@@ -365,6 +369,7 @@ files:
365
369
  - spec/lib/sinclair/matchers/change_instance_method_on_spec.rb
366
370
  - spec/lib/sinclair/matchers/change_instance_method_spec.rb
367
371
  - spec/lib/sinclair/matchers_spec.rb
372
+ - spec/lib/sinclair/method_builder/base_spec.rb
368
373
  - spec/lib/sinclair/method_builder/block_method_builder_spec.rb
369
374
  - spec/lib/sinclair/method_builder/call_method_builder_spec.rb
370
375
  - spec/lib/sinclair/method_builder/string_method_builder_spec.rb
@@ -425,6 +430,7 @@ files:
425
430
  - spec/support/shared_examples/config_factory.rb
426
431
  - spec/support/shared_examples/env_settable.rb
427
432
  - spec/support/shared_examples/instance_method_definition.rb
433
+ - spec/support/shared_examples/sinclair.rb
428
434
  homepage: https://github.com/darthjee/sinclair
429
435
  licenses: []
430
436
  metadata: {}