sinclair 1.16.3 → 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: b50c8756a84388173ff948946c6551420db72afa180b707754de4db5aebfc37e
4
- data.tar.gz: d1824371cc9e9e272c8d26c5a24ce836af12b3febdd9943a1dae7a345f8947b9
3
+ metadata.gz: 19c1884db0b54297baef8febbc49ed4ed07e97603af7553ddfa90ab02c2fa836
4
+ data.tar.gz: 880bf1db3d2b09f95d0103622a6ab42b62cbed746447c9435168eaaa18359042
5
5
  SHA512:
6
- metadata.gz: 8f5c96721ae43d84a713bc6535b251b5e06e17acc60da8f4fd03bb1df63f7a56f3a72c68ace5dd8856f3bc0884e29c0f807befc5cfe8705165f64345d01ea3d8
7
- data.tar.gz: d27893bf77a520bcdea71e4813cea5a6ef03ed168ec7e95e29c94a23c901b5bceaaa6c914801a9d4dda802e65365aa4ec0171704303011baff41810bdaf8a3b2
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: [1.16.3](https://github.com/darthjee/sinclair/tree/1.16.3)
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/1.16.3...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/1.16.3](https://www.rubydoc.info/gems/sinclair/1.16.3)
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 = '1.16.3'
4
+ VERSION = '2.0.1'
5
5
  end
data/sinclair.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
20
20
  gem.require_paths = ['lib']
21
21
 
22
- gem.add_runtime_dependency 'activesupport', '~> 5.2.0'
22
+ gem.add_runtime_dependency 'activesupport', '~> 7.0.4'
23
23
 
24
24
  gem.add_development_dependency 'bundler', '>= 2.3.25'
25
25
  gem.add_development_dependency 'pry', '0.14.1'
@@ -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: 1.16.3
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-10 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
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.0
19
+ version: 7.0.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.0
26
+ version: 7.0.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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