sinclair 1.16.1 → 1.16.2

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: '0633819d57447ccb757e81a154d58e8b5c47ed5fb49a6b738b6e3b27801ceeb0'
4
- data.tar.gz: 0b50ae42aa0c487d3ae12d5e2b0c0933b4cff0040d7635340d82a5122a038c47
3
+ metadata.gz: 474f2601f89233396a82476209781ffb365ceb839756d70defeadade14a0b07e
4
+ data.tar.gz: 0de9aa5777826bb36c69e7499fce572f7dabcb2fff8d3fb322de75f71edcbf41
5
5
  SHA512:
6
- metadata.gz: a72bfc2c48a33ef60fa56a4a7dd8009a12737752ffa3075ef58a50f43968779155f95b095afc7b01d2f9172b2f6d88a2cdf1f2b1e010036686cdb4be7ae376fb
7
- data.tar.gz: 3e0e0a9a8bc66d1d13c427895bd9473d1a984b30bd66a8fbc961d2f80d9f54910381a2ec6d3f1ab256590a9c6aaf559b71bba921f8c1bd2466501c02e835ced0
6
+ metadata.gz: d1b82cbba327c1310c7783b3223acb1d7d412dfc8af26f98993499104cd8aac30ba06cfc334f433c59d052631c7d28a76638b6894d8247811ad682d95a8d2c90
7
+ data.tar.gz: bf2039f736954188ee656c8f6d871a4d10546f9a9b6e80f5bdaa88f8a22cbf4ea94a650bb5d1101b4d68ab3fbf1553701d70f27613c8233f0fe699fc619add0f
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.1](https://github.com/darthjee/sinclair/tree/1.16.1)
18
+ Current Release: [1.16.2](https://github.com/darthjee/sinclair/tree/1.16.2)
19
19
 
20
- [Next release](https://github.com/darthjee/sinclair/compare/1.16.1...master)
20
+ [Next release](https://github.com/darthjee/sinclair/compare/1.16.2...master)
21
21
 
22
22
  Yard Documentation
23
23
  -------------------
24
- [https://www.rubydoc.info/gems/sinclair/1.16.1](https://www.rubydoc.info/gems/sinclair/1.16.1)
24
+ [https://www.rubydoc.info/gems/sinclair/1.16.2](https://www.rubydoc.info/gems/sinclair/1.16.2)
25
25
 
26
26
  Installation
27
27
  ---------------
@@ -30,11 +30,21 @@ class Sinclair
30
30
  def caster_for(key)
31
31
  return casters[key] if casters.key?(key)
32
32
 
33
- caster_for_class(key) || superclas_caster_for(key) || new { |value| value }
33
+ caster_for_class(key) || superclas_caster_for(key) || Sinclair::Caster.default
34
34
  end
35
35
 
36
36
  protected
37
37
 
38
+ # @private
39
+ # @api private
40
+ #
41
+ # Default caster that performs no casting returning the value itself
42
+ #
43
+ # @return [Caster]
44
+ def default
45
+ @default ||= new
46
+ end
47
+
38
48
  # @api private
39
49
  #
40
50
  # Returns a caster from the superclass
@@ -317,7 +317,7 @@ class Sinclair
317
317
 
318
318
  # @param block [Proc] Proc to be used when converting the value object
319
319
  def initialize(&block)
320
- @block = block.to_proc
320
+ @block = block&.to_proc
321
321
  end
322
322
 
323
323
  # Cast a value using the given the set +block+
@@ -348,6 +348,8 @@ class Sinclair
348
348
  #
349
349
  # @return [Object] the result of the converting block
350
350
  def cast(value, **opts)
351
+ return value unless block
352
+
351
353
  options = opts.select do |key, _|
352
354
  options_keys.include?(key)
353
355
  end
@@ -99,14 +99,13 @@ class Sinclair
99
99
 
100
100
  private
101
101
 
102
- attr_reader :attributes
103
-
104
102
  # @private
105
103
  # @api private
106
- # @method attributes
104
+ # @attr_reader attributes
107
105
  #
108
106
  # attributes relevant for checking difference
109
107
  #
110
108
  # @return [Set<Symbol,String>]
109
+ attr_reader :attributes
111
110
  end
112
111
  end
@@ -36,13 +36,14 @@ class Sinclair
36
36
 
37
37
  private
38
38
 
39
- attr_reader :klass
40
- # @method klass
39
+ # @attr_reader klass
41
40
  # @private
42
41
  # @api private
42
+ # @!visibility public
43
43
  #
44
44
  # class to receive the method
45
45
  #
46
46
  # @return [Class]
47
+ attr_reader :klass
47
48
  end
48
49
  end
@@ -16,7 +16,7 @@ class Sinclair
16
16
  autoload :ParameterHelper, 'sinclair/method_definition/parameter_helper'
17
17
  autoload :Stringifier, 'sinclair/method_definition/stringifier'
18
18
 
19
- # @method name
19
+ # @attr_reader name
20
20
  #
21
21
  # name of the method
22
22
  #
@@ -43,14 +43,14 @@ class Sinclair
43
43
 
44
44
  private
45
45
 
46
- attr_reader :attributes
47
- # @method attributes
48
46
  # @api private
49
47
  # @private
48
+ # @attr_reader attributes
50
49
  #
51
50
  # Options attributes
52
51
  #
53
52
  # @return [Hash<Symbol.Object>]
53
+ attr_reader :attributes
54
54
 
55
55
  # Add all methods for options
56
56
  #
@@ -30,7 +30,9 @@ class Sinclair
30
30
  module OptionsParser
31
31
  private
32
32
 
33
+ # @attr_reader options
33
34
  # @!visibility public
35
+ # @private
34
36
  #
35
37
  # Options hash
36
38
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Sinclair
4
- VERSION = '1.16.1'
4
+ VERSION = '1.16.2'
5
5
  end
data/lib/sinclair.rb CHANGED
@@ -457,14 +457,14 @@ class Sinclair
457
457
 
458
458
  private
459
459
 
460
- attr_reader :klass
461
- # @method klass
460
+ # @!visibility public
462
461
  # @api private
463
462
  # @private
464
463
  #
465
464
  # Class that will receive the methods
466
465
  #
467
466
  # @return [Class]
467
+ attr_reader :klass
468
468
 
469
469
  # @private
470
470
  # @api private
@@ -6,8 +6,29 @@ describe Sinclair::Caster do
6
6
  subject(:caster) { caster_class.new(&method_name) }
7
7
 
8
8
  let(:caster_class) { Class.new(described_class) }
9
+ let(:value) { values.sample }
10
+ let(:values) do
11
+ [Random.rand, 'some string', { key: 10 }, Object.new, Class.new, [2, 3]]
12
+ end
13
+
14
+ describe '#cast' do
15
+ context 'when no block is given' do
16
+ subject(:caster) { caster_class.new }
17
+
18
+ context 'when no options are given' do
19
+ it 'returns the value' do
20
+ expect(caster.cast(value)).to be(value)
21
+ end
22
+ end
23
+
24
+ context 'when options are given' do
25
+ it 'returns the value' do
26
+ expect(caster.cast(value, key: :value))
27
+ .to be(value)
28
+ end
29
+ end
30
+ end
9
31
 
10
- describe '.cast' do
11
32
  context 'when no options are given and the block accepts none' do
12
33
  let(:method_name) { :to_s }
13
34
 
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.1
4
+ version: 1.16.2
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-02 00:00:00.000000000 Z
11
+ date: 2023-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport