sinclair 1.16.1 → 1.16.2
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/README.md +3 -3
- data/lib/sinclair/caster/class_methods.rb +11 -1
- data/lib/sinclair/caster.rb +3 -1
- data/lib/sinclair/equals_checker.rb +2 -3
- data/lib/sinclair/method_builder.rb +3 -2
- data/lib/sinclair/method_definition.rb +1 -1
- data/lib/sinclair/options/builder.rb +2 -2
- data/lib/sinclair/options_parser.rb +2 -0
- data/lib/sinclair/version.rb +1 -1
- data/lib/sinclair.rb +2 -2
- data/spec/lib/sinclair/caster_spec.rb +22 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 474f2601f89233396a82476209781ffb365ceb839756d70defeadade14a0b07e
|
|
4
|
+
data.tar.gz: 0de9aa5777826bb36c69e7499fce572f7dabcb2fff8d3fb322de75f71edcbf41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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.
|
|
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.
|
|
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) ||
|
|
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
|
data/lib/sinclair/caster.rb
CHANGED
|
@@ -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
|
|
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
|
-
# @
|
|
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
|
|
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
|
|
@@ -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
|
#
|
data/lib/sinclair/version.rb
CHANGED
data/lib/sinclair.rb
CHANGED
|
@@ -457,14 +457,14 @@ class Sinclair
|
|
|
457
457
|
|
|
458
458
|
private
|
|
459
459
|
|
|
460
|
-
|
|
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.
|
|
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-
|
|
11
|
+
date: 2023-05-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|