sinclair 1.10.0 → 1.12.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 +6 -0
- data/README.md +444 -324
- data/config/check_specs.yml +5 -5
- data/config/yardstick.yml +4 -0
- data/lib/sinclair/matchers/add_class_method.rb +0 -1
- data/lib/sinclair/method_builder/base.rb +32 -2
- data/lib/sinclair/method_builder/block_method_builder.rb +1 -12
- data/lib/sinclair/method_builder/call_method_builder.rb +10 -27
- data/lib/sinclair/method_builder/string_method_builder.rb +2 -29
- data/lib/sinclair/method_builder.rb +4 -20
- data/lib/sinclair/method_definition/block_definition.rb +2 -0
- data/lib/sinclair/method_definition/call_definition.rb +15 -18
- data/lib/sinclair/method_definition/parameter_builder.rb +89 -0
- data/lib/sinclair/method_definition/parameter_helper.rb +124 -0
- data/lib/sinclair/method_definition/string_definition.rb +26 -2
- data/lib/sinclair/method_definition.rb +42 -3
- data/lib/sinclair/method_definitions.rb +20 -22
- data/lib/sinclair/version.rb +1 -1
- data/lib/sinclair.rb +149 -62
- data/spec/integration/readme/sinclair/types_of_definition_spec.rb +61 -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_spec.rb +0 -83
- data/spec/lib/sinclair/method_builder/base_spec.rb +15 -0
- data/spec/lib/sinclair/method_builder/string_method_builder_spec.rb +24 -1
- data/spec/lib/sinclair/method_definition/call_definition_spec.rb +14 -17
- data/spec/lib/sinclair/method_definition/parameter_builder_spec.rb +81 -0
- data/spec/lib/sinclair/method_definition/string_definition_spec.rb +60 -29
- data/spec/lib/sinclair/method_definition_spec.rb +77 -2
- data/spec/lib/sinclair/method_definitions_spec.rb +15 -16
- data/spec/lib/sinclair_spec.rb +6 -160
- data/spec/support/models/dummy_builder.rb +5 -1
- data/spec/support/models/dummy_class_builder.rb +4 -0
- data/spec/support/models/person.rb +1 -1
- data/spec/support/shared_examples/sinclair.rb +118 -0
- metadata +11 -2
@@ -0,0 +1,118 @@
|
|
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
|
+
|
30
|
+
context 'when the method has custom parameters' do
|
31
|
+
it 'creates a method using the string definition' do
|
32
|
+
expect(object.sum(10, 23)).to eq(33)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when describing a method using a block specific type' do
|
38
|
+
it 'creates a method with the block' do
|
39
|
+
expect(object.type_block).to eq(3)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when describing a method using a string specific type' do
|
44
|
+
it 'creates a method with the string' do
|
45
|
+
expect(object.type_string).to eq(10)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when describing a method using a call specific type for attr_acessor' do
|
50
|
+
let(:value) { Random.rand }
|
51
|
+
|
52
|
+
it 'creates acessors' do
|
53
|
+
expect { object.some_attribute = value }
|
54
|
+
.to change(object, :some_attribute)
|
55
|
+
.from(nil).to(value)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when passing options' do
|
60
|
+
let(:options) { { increment: 2 } }
|
61
|
+
|
62
|
+
it 'parses the options' do
|
63
|
+
expect(object.defined).to eq(2)
|
64
|
+
expect(object.defined).to eq(4)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when adding methods to a regular builder' do
|
70
|
+
context 'when declaring a method with a block' do
|
71
|
+
before do
|
72
|
+
builder.public_send(method_name, :blocked) { 1 }
|
73
|
+
builder.public_send(method_name, :blocked) { 2 }
|
74
|
+
builder.build
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'respect the order of method addtion' do
|
78
|
+
expect(object.blocked).to eq(2)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when declaring a method string' do
|
83
|
+
before do
|
84
|
+
builder.public_send(method_name, :string, '1')
|
85
|
+
builder.public_send(method_name, :string, '2')
|
86
|
+
builder.build
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'respect the order of method addtion' do
|
90
|
+
expect(object.string).to eq(2)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when declaring block and string' do
|
95
|
+
before do
|
96
|
+
builder.public_send(method_name, :value) { 1 }
|
97
|
+
builder.public_send(method_name, :value, '2')
|
98
|
+
builder.build
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'respect the order of method addtion' do
|
102
|
+
expect(object.value).to eq(2)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'when declaring string and block' do
|
107
|
+
before do
|
108
|
+
builder.public_send(method_name, :value, '1')
|
109
|
+
builder.public_send(method_name, :value) { 2 }
|
110
|
+
builder.build
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'respect the order of method addtion' do
|
114
|
+
expect(object.value).to eq(2)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
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.12.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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -308,6 +308,8 @@ files:
|
|
308
308
|
- lib/sinclair/method_definition/block_definition.rb
|
309
309
|
- lib/sinclair/method_definition/block_helper.rb
|
310
310
|
- lib/sinclair/method_definition/call_definition.rb
|
311
|
+
- lib/sinclair/method_definition/parameter_builder.rb
|
312
|
+
- lib/sinclair/method_definition/parameter_helper.rb
|
311
313
|
- lib/sinclair/method_definition/string_definition.rb
|
312
314
|
- lib/sinclair/method_definitions.rb
|
313
315
|
- lib/sinclair/options.rb
|
@@ -324,8 +326,11 @@ files:
|
|
324
326
|
- spec/integration/readme/sinclair/env_settable_spec.rb
|
325
327
|
- spec/integration/readme/sinclair/matchers_spec.rb
|
326
328
|
- spec/integration/readme/sinclair/options_spec.rb
|
329
|
+
- spec/integration/readme/sinclair/types_of_definition_spec.rb
|
327
330
|
- spec/integration/readme/sinclair_spec.rb
|
328
331
|
- spec/integration/yard/my_builder_spec.rb
|
332
|
+
- spec/integration/yard/sinclair/add_class_method_spec.rb
|
333
|
+
- spec/integration/yard/sinclair/add_method_spec.rb
|
329
334
|
- spec/integration/yard/sinclair/comparable_spec.rb
|
330
335
|
- spec/integration/yard/sinclair/config_builder_spec.rb
|
331
336
|
- spec/integration/yard/sinclair/config_class_spec.rb
|
@@ -334,6 +339,7 @@ files:
|
|
334
339
|
- spec/integration/yard/sinclair/configurable_spec.rb
|
335
340
|
- spec/integration/yard/sinclair/env_settable_spec.rb
|
336
341
|
- spec/integration/yard/sinclair/equals_checker_spec.rb
|
342
|
+
- spec/integration/yard/sinclair/eval_and_add_method_spec.rb
|
337
343
|
- spec/integration/yard/sinclair/input_hash_spec.rb
|
338
344
|
- spec/integration/yard/sinclair/matchers/add_class_method_spec.rb
|
339
345
|
- spec/integration/yard/sinclair/matchers/add_class_method_to_spec.rb
|
@@ -365,6 +371,7 @@ files:
|
|
365
371
|
- spec/lib/sinclair/matchers/change_instance_method_on_spec.rb
|
366
372
|
- spec/lib/sinclair/matchers/change_instance_method_spec.rb
|
367
373
|
- spec/lib/sinclair/matchers_spec.rb
|
374
|
+
- spec/lib/sinclair/method_builder/base_spec.rb
|
368
375
|
- spec/lib/sinclair/method_builder/block_method_builder_spec.rb
|
369
376
|
- spec/lib/sinclair/method_builder/call_method_builder_spec.rb
|
370
377
|
- spec/lib/sinclair/method_builder/string_method_builder_spec.rb
|
@@ -372,6 +379,7 @@ files:
|
|
372
379
|
- spec/lib/sinclair/method_definition/block_definition_spec.rb
|
373
380
|
- spec/lib/sinclair/method_definition/block_helper_spec.rb
|
374
381
|
- spec/lib/sinclair/method_definition/call_definition_spec.rb
|
382
|
+
- spec/lib/sinclair/method_definition/parameter_builder_spec.rb
|
375
383
|
- spec/lib/sinclair/method_definition/string_definition_spec.rb
|
376
384
|
- spec/lib/sinclair/method_definition_spec.rb
|
377
385
|
- spec/lib/sinclair/method_definitions_spec.rb
|
@@ -425,6 +433,7 @@ files:
|
|
425
433
|
- spec/support/shared_examples/config_factory.rb
|
426
434
|
- spec/support/shared_examples/env_settable.rb
|
427
435
|
- spec/support/shared_examples/instance_method_definition.rb
|
436
|
+
- spec/support/shared_examples/sinclair.rb
|
428
437
|
homepage: https://github.com/darthjee/sinclair
|
429
438
|
licenses: []
|
430
439
|
metadata: {}
|