sinclair 1.15.0 → 1.16.0

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: bd10c98e0ec9983e0bd34a8b438126cc391ae667c9e7d5b7ca62f473c5296aea
4
- data.tar.gz: f1bffcf49524f9dc05ee27e7510c4e0a76be23b674642fcfa2b10cfdb9f43a82
3
+ metadata.gz: 54cfb901ecd8185d00862d7c0b5a99e9cb626d2bbadf45db59553ae980ef9dc1
4
+ data.tar.gz: 7f0f0a291a659fbc5eaa0d6b56a8bc0f2dfe08b3c0a0d290dad2a6136c7ccc53
5
5
  SHA512:
6
- metadata.gz: f3afe247b25b8b10f692227c3d5c031e4d6fd04f8aa00e021d0aa8d5813d9cba75c05b4a7d8aae6cc5b6be96d7de404becf35e9391db92c3ceadfc2804f72ce5
7
- data.tar.gz: c80cee176cd24ecce3410fa6a64789ca3f52789bce24d558b421751fb6c74a4bf5c86eb1246e48d09abbad962e3bc6f965f1dcf09beae9eca68a198d4e969771
6
+ metadata.gz: d788efed427695e2b001e7b38cc7fa4ef41fb8f6e6b855d321e88f24cb7c97b71b7f4d2622041a5f36ed9921b88513bb26beb4d3b0f11c37a19425a2d1698d9b
7
+ data.tar.gz: 66f7170ee3a639fa43219f10f3c984369d72ac3e58f182ac00bf0fecf947efa0e5f25107cffa45db30048366085c7c329cd214b5ed5659d854af93f0588b264b
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.15.0](https://github.com/darthjee/sinclair/tree/1.15.0)
18
+ Current Release: [1.16.0](https://github.com/darthjee/sinclair/tree/1.16.0)
19
19
 
20
- [Next release](https://github.com/darthjee/sinclair/compare/1.15.0...master)
20
+ [Next release](https://github.com/darthjee/sinclair/compare/1.16.0...master)
21
21
 
22
22
  Yard Documentation
23
23
  -------------------
24
- [https://www.rubydoc.info/gems/sinclair/1.15.0](https://www.rubydoc.info/gems/sinclair/1.15.0)
24
+ [https://www.rubydoc.info/gems/sinclair/1.16.0](https://www.rubydoc.info/gems/sinclair/1.16.0)
25
25
 
26
26
  Installation
27
27
  ---------------
@@ -62,6 +62,8 @@ class Sinclair
62
62
  #
63
63
  # @return [Caster]
64
64
  def caster_for_class(klass)
65
+ return unless klass.is_a?(Class) || klass.is_a?(Module)
66
+
65
67
  class_casters.find do |klazz, _|
66
68
  klass <= klazz
67
69
  end&.second
@@ -24,7 +24,11 @@ class Sinclair
24
24
  # The master caster never checks with its an
25
25
  #
26
26
  # @example
27
- # class MyCaster < Sinclair::Caster
27
+ # class BaseCaster < Sinclair::Caster
28
+ # cast_with(:string, :to_s)
29
+ # end
30
+ #
31
+ # class MyCaster < BaseCaster
28
32
  # end
29
33
  #
30
34
  # MyCaster.cast(10, :string) # returns '10'
@@ -373,9 +377,5 @@ class Sinclair
373
377
  #
374
378
  # @return [Proc]
375
379
  attr_reader :block
376
-
377
- cast_with(:string, :to_s)
378
- cast_with(:integer, :to_i)
379
- cast_with(:float, :to_f)
380
380
  end
381
381
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Sinclair
4
- VERSION = '1.15.0'
4
+ VERSION = '1.16.0'
5
5
  end
@@ -3,7 +3,13 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'yard Sinclair::Caster::ClassMethods' do
6
- let(:my_caster) { Class.new(Sinclair::Caster) }
6
+ let(:my_caster) { Class.new(superclass) }
7
+
8
+ let(:superclass) do
9
+ Class.new(Sinclair::Caster) do
10
+ cast_with(:string, :to_s)
11
+ end
12
+ end
7
13
 
8
14
  describe '.master_caster!' do
9
15
  it 'Making a class to be a master caster' do
@@ -3,7 +3,16 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Sinclair::Caster::ClassMethods do
6
- subject(:caster) { Class.new(Sinclair::Caster) }
6
+ subject(:caster) { Class.new(superclass) }
7
+
8
+ let(:superclass) do
9
+ Class.new(Sinclair::Caster) do
10
+ cast_with(:string, :to_s)
11
+ cast_with(:integer, :to_i)
12
+ cast_with(:float, :to_f)
13
+ cast_with(String, :to_s)
14
+ end
15
+ end
7
16
 
8
17
  describe '.cast_with' do
9
18
  let(:value) { instance_double('value', to_p: final_value) }
@@ -120,6 +129,19 @@ describe Sinclair::Caster::ClassMethods do
120
129
  end
121
130
 
122
131
  describe '.caster_for' do
132
+ context 'when nil key is given' do
133
+ let(:value) { values.sample }
134
+ let(:values) do
135
+ [Random.rand, 'some string', { key: 10 }, Object.new, Class.new, [2, 3]]
136
+ end
137
+
138
+ it { expect(caster.caster_for(nil)).to be_a(Sinclair::Caster) }
139
+
140
+ it 'returns the default caster' do
141
+ expect(caster.caster_for(nil).cast(value)).to eq(value)
142
+ end
143
+ end
144
+
123
145
  context 'when the key has been defined with a symbol key' do
124
146
  before { caster.cast_with(:problem, :to_p) }
125
147
 
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.15.0
4
+ version: 1.16.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-04-29 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport