sinclair 2.0.0 → 2.0.1

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: 5925279d520a736464493265a29b33212eb44c509ac5e08605b3dc49e26b9113
4
- data.tar.gz: f09c7b30adef51ee9b5e18dbda960a5f93e595686afb2b4a0774bd8eeab40fb8
3
+ metadata.gz: 19c1884db0b54297baef8febbc49ed4ed07e97603af7553ddfa90ab02c2fa836
4
+ data.tar.gz: 880bf1db3d2b09f95d0103622a6ab42b62cbed746447c9435168eaaa18359042
5
5
  SHA512:
6
- metadata.gz: 62cc94ccc49c52f06bedd28d12b62fb10ccb583f8d8b5fe48c24896e45979d36da2529349795dfbbdfe8d899565ec99520b23069654fa67abf3616251fd0a473
7
- data.tar.gz: d20e090b1b663d3fb5b333763c4002f99b55b204a7e90ddf2c287d737f2508fd7dfc1d388a57a8b6a99abe09f7087b37df2336928254a439c397a51fd3e9e319
6
+ metadata.gz: 6e2e7c8f8c0488e75d23ced4234c796da41cddba29e0f26087fc3522f232ccabfae08d1ac30a4eb1223463579fb371aa4e9ba7f3e4b9d1c6d05eaaae26b1d2ab
7
+ data.tar.gz: 4e9dbdb362d045182d4b28075153d08b708f01f3697dc8550fb29715dad135b245544a94f6a2db605f7e814460ab24126825e6d3c49c08a69e674b28cfa08902
data/README.md CHANGED
@@ -15,13 +15,13 @@ create custom comparators, configure your application, create powerfull options,
15
15
 
16
16
  Employing Sinclair in your applications helps you streamline your development workflow and enhance your development process through more efficient, cleaner code
17
17
 
18
- Current Release: [2.0.0](https://github.com/darthjee/sinclair/tree/2.0.0)
18
+ Current Release: [2.0.1](https://github.com/darthjee/sinclair/tree/2.0.1)
19
19
 
20
- [Next release](https://github.com/darthjee/sinclair/compare/2.0.0...master)
20
+ [Next release](https://github.com/darthjee/sinclair/compare/2.0.1...master)
21
21
 
22
22
  Yard Documentation
23
23
  -------------------
24
- [https://www.rubydoc.info/gems/sinclair/2.0.0](https://www.rubydoc.info/gems/sinclair/2.0.0)
24
+ [https://www.rubydoc.info/gems/sinclair/2.0.1](https://www.rubydoc.info/gems/sinclair/2.0.1)
25
25
 
26
26
  Installation
27
27
  ---------------
@@ -32,8 +32,8 @@ class Sinclair
32
32
  # model = MyPerson.new
33
33
  #
34
34
  # model.random_name # returns 'John 803 Doe'
35
- def build(klass, options = {}, &block)
36
- new(klass, options).tap do |builder|
35
+ def build(*args, **opts, &block)
36
+ new(*args, **opts).tap do |builder|
37
37
  builder.instance_eval(&block) if block_given?
38
38
  end.build
39
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Sinclair
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
5
5
  end
@@ -10,7 +10,7 @@ describe Sinclair::ClassMethods do
10
10
  let(:dummy_class) { Class.new }
11
11
  let(:builder_class) { Sinclair }
12
12
 
13
- describe '#build' do
13
+ describe '.build' do
14
14
  let(:block) do
15
15
  method_name = :some_method
16
16
  value = 1
@@ -21,13 +21,13 @@ describe Sinclair::ClassMethods do
21
21
  end
22
22
 
23
23
  it 'executes the block and builds' do
24
- expect { builder_class.build(dummy_class, options, &block) }
24
+ expect { builder_class.build(dummy_class, **options, &block) }
25
25
  .to add_method(:some_method).to(dummy_class)
26
26
  end
27
27
 
28
28
  context 'when the method is built and called' do
29
29
  before do
30
- builder_class.build(dummy_class, options, &block)
30
+ builder_class.build(dummy_class, **options, &block)
31
31
  end
32
32
 
33
33
  it 'returns the value' do
@@ -46,9 +46,29 @@ describe Sinclair::ClassMethods do
46
46
  end
47
47
 
48
48
  it 'executes the block and builds' do
49
- expect { builder_class.build(dummy_class, options) }
49
+ expect { builder_class.build(dummy_class, **options) }
50
50
  .to add_method(:some_method).to(dummy_class)
51
51
  end
52
52
  end
53
+
54
+ context 'when a block is given and initialization contains more arguments' do
55
+ let(:builder_class) { ComplexBuilder }
56
+ let(:value) { Random.rand(10..30) }
57
+ let(:power) { Random.rand(3..5) }
58
+ let(:result) { value**power }
59
+
60
+ it 'executes the block and builds' do
61
+ expect { builder_class.build(dummy_class, value, power, &:add_default) }
62
+ .to add_method(:result).to(dummy_class)
63
+ end
64
+
65
+ context 'when the method is called' do
66
+ before { builder_class.build(dummy_class, value, power, &:add_default) }
67
+
68
+ it 'returns the evaluated value' do
69
+ expect(instance.result).to eq(result)
70
+ end
71
+ end
72
+ end
53
73
  end
54
74
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ComplexBuilder < Sinclair
4
+ def initialize(klass, value, power)
5
+ @value = value
6
+ @power = power
7
+
8
+ super(klass)
9
+ end
10
+
11
+ def add_default
12
+ val = @value
13
+ pow = @power
14
+
15
+ add_method(:result) { val**pow }
16
+ end
17
+ 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: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-12 00:00:00.000000000 Z
11
+ date: 2023-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -421,6 +421,7 @@ files:
421
421
  - spec/support/models/builder_options.rb
422
422
  - spec/support/models/car.rb
423
423
  - spec/support/models/client.rb
424
+ - spec/support/models/complex_builder.rb
424
425
  - spec/support/models/connection_options.rb
425
426
  - spec/support/models/default_value.rb
426
427
  - spec/support/models/default_value_builder.rb