smart_types 0.7.1 → 0.8.1
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/.github/workflows/ci.yml +2 -4
- data/.rubocop.yml +7 -0
- data/CHANGELOG.md +31 -5
- data/Gemfile.lock +72 -67
- data/LICENSE.txt +1 -1
- data/README.md +25 -4
- data/lib/smart_core/types/primitive/factory/runtime_type_builder.rb +2 -2
- data/lib/smart_core/types/primitive/invariant_control/chain/result.rb +1 -1
- data/lib/smart_core/types/primitive/invariant_control/chain.rb +13 -1
- data/lib/smart_core/types/primitive/invariant_control/single.rb +11 -1
- data/lib/smart_core/types/primitive/invariant_control.rb +26 -1
- data/lib/smart_core/types/primitive/nilable_validator.rb +1 -1
- data/lib/smart_core/types/primitive/validator.rb +9 -5
- data/lib/smart_core/types/value/method.rb +4 -2
- data/lib/smart_core/types/value/range.rb +4 -2
- data/lib/smart_core/types/value/rational.rb +8 -3
- data/lib/smart_core/types/value/unbound_method.rb +4 -2
- data/lib/smart_core/types/version.rb +2 -2
- data/smart_types.gemspec +7 -7
- metadata +16 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ecaa56176fade082d67794d331c28cfb819e51a43d4e3dcce6b59f35cb2884b3
|
|
4
|
+
data.tar.gz: 511f1a70284b7f986de8d1c3cabbf40aa872bc00be68e9d151032db827c09cae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b89d4104c04d5cd36856fbc760f1a9c561d90b3b812531e31f5572a29f605b396fa95f69af89b00d52e85299b2f0f180bce736e69a75d4c4ab550ce595d7e51d
|
|
7
|
+
data.tar.gz: 2e94034f7b1073f28c46302b5a06344a9757142a09e5334109c804365c791f16f244dc27cfd785fe0c7eea6ec77bb04efae7cff10a77ca2595a11cdf91cad2da
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -16,14 +16,12 @@ jobs:
|
|
|
16
16
|
fail-fast: false
|
|
17
17
|
matrix:
|
|
18
18
|
ruby:
|
|
19
|
-
- version: 2.5
|
|
20
|
-
continue-on-error: false
|
|
21
|
-
- version: 2.6
|
|
22
|
-
continue-on-error: false
|
|
23
19
|
- version: 2.7
|
|
24
20
|
continue-on-error: false
|
|
25
21
|
- version: 3.0
|
|
26
22
|
continue-on-error: false
|
|
23
|
+
- version: 3.1
|
|
24
|
+
continue-on-error: false
|
|
27
25
|
- version: ruby-head
|
|
28
26
|
continue-on-error: true
|
|
29
27
|
- version: jruby-head
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
# [Unreleased]
|
|
5
|
+
- New types of `SmartCore::Types::Value` category:
|
|
6
|
+
- `SmartCore::Types::Value::UnboundMethod`;
|
|
7
|
+
- `SmartCore::Types::Value::Range`;
|
|
8
|
+
- `SmartCore::Types::Value::Rational`;
|
|
9
|
+
|
|
10
|
+
# [0.8.1] - 2026-07-03
|
|
11
|
+
### Changed
|
|
12
|
+
- Performance: faster `SmartCore::Types::Primitive#valid?` (the common validation path):
|
|
13
|
+
- `SmartCore::Types::Primitive::InvariantControl#simply_check` now short-circuits for types
|
|
14
|
+
without invariants (precomputed at build time) — the majority of types (e.g. `Value::String`,
|
|
15
|
+
`Protocol::InstanceOf`) define only a checker, so the empty-invariant iteration is skipped;
|
|
16
|
+
- `SmartCore::Types::Primitive::Validator#valid?` and `#validate` fetch `runtime_attributes`
|
|
17
|
+
once instead of twice;
|
|
18
|
+
- ~17–20% faster validation for `Value::String` and `Protocol::InstanceOf` (3M-iteration benchmark).
|
|
19
|
+
No public API or validation-semantics change.
|
|
20
|
+
|
|
21
|
+
# [0.8.0] - 2022-11-25
|
|
22
|
+
### Added
|
|
23
|
+
- New types of `SmartCore::Types::Value` category:
|
|
24
|
+
- `SmartCore::Types::Value::Method`
|
|
25
|
+
- Support for *Ruby@3.1*;
|
|
26
|
+
### Changed
|
|
27
|
+
- `SmartCore::Types::Primitive#valid?` now has no dependency on invariant control result object interface
|
|
28
|
+
(reduced object allocation count during validation: move from OOP-style to Procedure-style inside boolean methods);
|
|
29
|
+
- Updated development dependencies (see `Gemfile.lock` diffs);
|
|
30
|
+
- Support for *Ruby@2.4*, *Ruby@2.5* and *Ruby@2.6* has ended;
|
|
31
|
+
|
|
4
32
|
# [0.7.1] - 2022-08-31
|
|
5
33
|
### Fixed
|
|
6
|
-
-
|
|
7
|
-
`TruffleRuby` implementation makes `initialize_clone` method private by default even if your manually defined method is implicitly public
|
|
34
|
+
- **TruffelRuby**: fixed `NoMethodError: private method 'initialize_clone'` failing on type object duplication and cloning (`#dup` and `#clone`).
|
|
35
|
+
`TruffleRuby` implementation makes `initialize_clone` method private by default even if your manually defined method is implicitly public
|
|
36
|
+
(see `SmartCore::Types::Primitive::Factory::RuntimeTypeBuilder.initialize_clone` and `SmartCore::Types::Primitive#initialize_copy`).
|
|
8
37
|
To fix this we should explicitly define our method as a public method (`public def initialize_clone`).
|
|
9
|
-
```
|
|
10
|
-
NoMethodError: private method `initialize_clone' called for SmartCore::Types::Primitive::Factory::RuntimeTypeBuilder:Module
|
|
11
|
-
```
|
|
12
38
|
|
|
13
39
|
# [0.7.0] - 2021-11-22
|
|
14
40
|
### Added
|
data/Gemfile.lock
CHANGED
|
@@ -1,109 +1,114 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
smart_types (0.
|
|
5
|
-
smart_engine (~> 0.
|
|
4
|
+
smart_types (0.8.1)
|
|
5
|
+
smart_engine (~> 0.17)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activesupport (
|
|
10
|
+
activesupport (7.0.5)
|
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
12
12
|
i18n (>= 1.6, < 2)
|
|
13
13
|
minitest (>= 5.1)
|
|
14
14
|
tzinfo (~> 2.0)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
rubocop (=
|
|
18
|
-
rubocop-
|
|
19
|
-
rubocop-
|
|
20
|
-
rubocop-
|
|
21
|
-
rubocop-
|
|
22
|
-
|
|
15
|
+
armitage-rubocop (1.51.0.4)
|
|
16
|
+
rubocop (= 1.51.0)
|
|
17
|
+
rubocop-capybara (= 2.18.0)
|
|
18
|
+
rubocop-factory_bot (= 2.23.1)
|
|
19
|
+
rubocop-performance (= 1.18.0)
|
|
20
|
+
rubocop-rails (= 2.19.1)
|
|
21
|
+
rubocop-rake (= 0.6.0)
|
|
22
|
+
rubocop-rspec (= 2.22.0)
|
|
23
|
+
ast (2.4.2)
|
|
23
24
|
coderay (1.1.3)
|
|
24
|
-
concurrent-ruby (1.
|
|
25
|
-
diff-lcs (1.
|
|
26
|
-
docile (1.
|
|
27
|
-
i18n (1.
|
|
25
|
+
concurrent-ruby (1.2.2)
|
|
26
|
+
diff-lcs (1.5.0)
|
|
27
|
+
docile (1.4.0)
|
|
28
|
+
i18n (1.13.0)
|
|
28
29
|
concurrent-ruby (~> 1.0)
|
|
30
|
+
json (2.6.3)
|
|
29
31
|
method_source (1.0.0)
|
|
30
|
-
minitest (5.
|
|
31
|
-
parallel (1.
|
|
32
|
-
parser (3.
|
|
32
|
+
minitest (5.18.0)
|
|
33
|
+
parallel (1.23.0)
|
|
34
|
+
parser (3.2.2.1)
|
|
33
35
|
ast (~> 2.4.1)
|
|
34
|
-
pry (0.
|
|
36
|
+
pry (0.14.2)
|
|
35
37
|
coderay (~> 1.1)
|
|
36
38
|
method_source (~> 1.0)
|
|
37
|
-
rack (
|
|
38
|
-
rainbow (3.
|
|
39
|
-
rake (13.0.
|
|
40
|
-
regexp_parser (2.0
|
|
41
|
-
rexml (3.2.
|
|
42
|
-
rspec (3.
|
|
43
|
-
rspec-core (~> 3.
|
|
44
|
-
rspec-expectations (~> 3.
|
|
45
|
-
rspec-mocks (~> 3.
|
|
46
|
-
rspec-core (3.
|
|
47
|
-
rspec-support (~> 3.
|
|
48
|
-
rspec-expectations (3.
|
|
39
|
+
rack (3.0.7)
|
|
40
|
+
rainbow (3.1.1)
|
|
41
|
+
rake (13.0.6)
|
|
42
|
+
regexp_parser (2.8.0)
|
|
43
|
+
rexml (3.2.5)
|
|
44
|
+
rspec (3.12.0)
|
|
45
|
+
rspec-core (~> 3.12.0)
|
|
46
|
+
rspec-expectations (~> 3.12.0)
|
|
47
|
+
rspec-mocks (~> 3.12.0)
|
|
48
|
+
rspec-core (3.12.2)
|
|
49
|
+
rspec-support (~> 3.12.0)
|
|
50
|
+
rspec-expectations (3.12.3)
|
|
49
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
50
|
-
rspec-support (~> 3.
|
|
51
|
-
rspec-mocks (3.
|
|
52
|
+
rspec-support (~> 3.12.0)
|
|
53
|
+
rspec-mocks (3.12.5)
|
|
52
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
53
|
-
rspec-support (~> 3.
|
|
54
|
-
rspec-support (3.
|
|
55
|
-
rubocop (1.
|
|
55
|
+
rspec-support (~> 3.12.0)
|
|
56
|
+
rspec-support (3.12.0)
|
|
57
|
+
rubocop (1.51.0)
|
|
58
|
+
json (~> 2.3)
|
|
56
59
|
parallel (~> 1.10)
|
|
57
|
-
parser (>= 2.
|
|
60
|
+
parser (>= 3.2.0.0)
|
|
58
61
|
rainbow (>= 2.2.2, < 4.0)
|
|
59
62
|
regexp_parser (>= 1.8, < 3.0)
|
|
60
|
-
rexml
|
|
61
|
-
rubocop-ast (>= 1.
|
|
63
|
+
rexml (>= 3.2.5, < 4.0)
|
|
64
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
62
65
|
ruby-progressbar (~> 1.7)
|
|
63
|
-
unicode-display_width (>=
|
|
64
|
-
rubocop-ast (1.
|
|
65
|
-
parser (>= 2.
|
|
66
|
-
rubocop-
|
|
67
|
-
rubocop (
|
|
66
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
67
|
+
rubocop-ast (1.28.1)
|
|
68
|
+
parser (>= 3.2.1.0)
|
|
69
|
+
rubocop-capybara (2.18.0)
|
|
70
|
+
rubocop (~> 1.41)
|
|
71
|
+
rubocop-factory_bot (2.23.1)
|
|
72
|
+
rubocop (~> 1.33)
|
|
73
|
+
rubocop-performance (1.18.0)
|
|
74
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
68
75
|
rubocop-ast (>= 0.4.0)
|
|
69
|
-
rubocop-rails (2.
|
|
76
|
+
rubocop-rails (2.19.1)
|
|
70
77
|
activesupport (>= 4.2.0)
|
|
71
78
|
rack (>= 1.1)
|
|
72
|
-
rubocop (>=
|
|
73
|
-
rubocop-rake (0.
|
|
74
|
-
rubocop
|
|
75
|
-
rubocop-rspec (2.1.0)
|
|
79
|
+
rubocop (>= 1.33.0, < 2.0)
|
|
80
|
+
rubocop-rake (0.6.0)
|
|
76
81
|
rubocop (~> 1.0)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
rubocop-rspec (2.22.0)
|
|
83
|
+
rubocop (~> 1.33)
|
|
84
|
+
rubocop-capybara (~> 2.17)
|
|
85
|
+
rubocop-factory_bot (~> 2.22)
|
|
86
|
+
ruby-progressbar (1.13.0)
|
|
87
|
+
simplecov (0.22.0)
|
|
80
88
|
docile (~> 1.1)
|
|
81
89
|
simplecov-html (~> 0.11)
|
|
82
90
|
simplecov_json_formatter (~> 0.1)
|
|
83
91
|
simplecov-html (0.12.3)
|
|
84
92
|
simplecov-lcov (0.8.0)
|
|
85
|
-
simplecov_json_formatter (0.1.
|
|
86
|
-
smart_engine (0.
|
|
87
|
-
tzinfo (2.0.
|
|
93
|
+
simplecov_json_formatter (0.1.4)
|
|
94
|
+
smart_engine (0.17.0)
|
|
95
|
+
tzinfo (2.0.6)
|
|
88
96
|
concurrent-ruby (~> 1.0)
|
|
89
|
-
unicode-display_width (
|
|
90
|
-
zeitwerk (2.4.2)
|
|
97
|
+
unicode-display_width (2.4.2)
|
|
91
98
|
|
|
92
99
|
PLATFORMS
|
|
93
|
-
arm64-darwin-
|
|
94
|
-
x86_64-
|
|
95
|
-
x86_64-darwin-20
|
|
96
|
-
x86_64-darwin-21
|
|
100
|
+
arm64-darwin-22
|
|
101
|
+
x86_64-linux
|
|
97
102
|
|
|
98
103
|
DEPENDENCIES
|
|
99
|
-
armitage-rubocop (~> 1.
|
|
100
|
-
bundler (~> 2.
|
|
101
|
-
pry (~> 0.
|
|
104
|
+
armitage-rubocop (~> 1.51)
|
|
105
|
+
bundler (~> 2.4)
|
|
106
|
+
pry (~> 0.14)
|
|
102
107
|
rake (~> 13.0)
|
|
103
|
-
rspec (~> 3.
|
|
104
|
-
simplecov (~> 0.
|
|
108
|
+
rspec (~> 3.12)
|
|
109
|
+
simplecov (~> 0.22)
|
|
105
110
|
simplecov-lcov (~> 0.8)
|
|
106
111
|
smart_types!
|
|
107
112
|
|
|
108
113
|
BUNDLED WITH
|
|
109
|
-
2.
|
|
114
|
+
2.4.13
|
data/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020-
|
|
3
|
+
Copyright (c) 2020-2024 Rustam Ibragimov
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
|
@@ -102,12 +102,16 @@ SmartCore::Types::Value::Array
|
|
|
102
102
|
SmartCore::Types::Value::Set
|
|
103
103
|
SmartCore::Types::Value::Hash
|
|
104
104
|
SmartCore::Types::Value::Proc
|
|
105
|
+
SmartCore::Types::Value::Range
|
|
106
|
+
SmartCore::Types::Value::Rational
|
|
105
107
|
SmartCore::Types::Value::Class
|
|
106
108
|
SmartCore::Types::Value::Module
|
|
107
109
|
SmartCore::Types::Value::Time
|
|
108
110
|
SmartCore::Types::Value::DateTime
|
|
109
111
|
SmartCore::Types::Value::Date
|
|
110
112
|
SmartCore::Types::Value::TimeBased
|
|
113
|
+
SmartCore::Types::Value::Method
|
|
114
|
+
SmartCore::Types::Value::UnboundMethod
|
|
111
115
|
```
|
|
112
116
|
|
|
113
117
|
---
|
|
@@ -388,6 +392,8 @@ SmartCore::Types::Value::CryptoString = SmartCore::Types::Value::NumberdString &
|
|
|
388
392
|
|
|
389
393
|
- migrate to `Github Actions`;
|
|
390
394
|
|
|
395
|
+
- an ability to cast `nil` to `nil` if `nil` is passed (example: `String.nilable_cast(nil) # => nil` and `String.cast(nil) # => ""`);
|
|
396
|
+
|
|
391
397
|
- support for `block`-attribute in runtime attributes;
|
|
392
398
|
|
|
393
399
|
- type configuration:
|
|
@@ -495,17 +501,20 @@ end
|
|
|
495
501
|
SmartCore::Types::Value::Date.cast('2020-01-01', { iso: :rfc3339 })
|
|
496
502
|
```
|
|
497
503
|
|
|
504
|
+
- custom type categories (an ability to register your own type category)
|
|
505
|
+
|
|
506
|
+
```ruby
|
|
507
|
+
SmartCore::Types.define_category(:YourCategoryName)
|
|
508
|
+
SmartCore::Types::YourCategoryName.define_type(:YourNewType) { ... }
|
|
509
|
+
```
|
|
510
|
+
|
|
498
511
|
- new types:
|
|
499
512
|
|
|
500
513
|
```ruby
|
|
501
|
-
SmartCore::Types::Value::Method
|
|
502
|
-
SmartCore::Types::Value::UnboundMethod
|
|
503
514
|
SmartCore::Types::Value::Enumerable
|
|
504
515
|
SmartCore::Types::Value::Comparable
|
|
505
516
|
SmartCore::Types::Value::Enumerator
|
|
506
517
|
SmartCore::Types::Value::EnumeratorChain
|
|
507
|
-
SmartCore::Types::Value::Range
|
|
508
|
-
SmartCore::Types::Value::Rational
|
|
509
518
|
SmartCore::Types::Value::SortedSet
|
|
510
519
|
SmartCore::Types::Value::IO
|
|
511
520
|
SmartCore::Types::Value::StringIO
|
|
@@ -525,6 +534,18 @@ SmartCore::Types::Behavior::Truthy
|
|
|
525
534
|
SmartCore::Types::Behavior::Falsy
|
|
526
535
|
```
|
|
527
536
|
|
|
537
|
+
```ruby
|
|
538
|
+
# Common types:
|
|
539
|
+
SmartCore::Types::Common::UUDv4
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
```ruby
|
|
543
|
+
# think about:
|
|
544
|
+
Clonable # for example, you can not clone or duplicate Method-objects
|
|
545
|
+
Duplicable
|
|
546
|
+
Allocatable # for example, Method object can not be allocated with #allocate method
|
|
547
|
+
```
|
|
548
|
+
|
|
528
549
|
- `#sum` alias for `|` and `#mult` alias for `&` (with a support for type name definition and other API);
|
|
529
550
|
|
|
530
551
|
- type category in invariant error codes:
|
|
@@ -29,7 +29,7 @@ module SmartCore::Types::Primitive::Factory::RuntimeTypeBuilder
|
|
|
29
29
|
# @api private
|
|
30
30
|
# @since 0.3.0
|
|
31
31
|
# @version 0.7.1
|
|
32
|
-
# rubocop:disable Metrics/AbcSize, Layout/LineLength
|
|
32
|
+
# rubocop:disable Style/AccessModifierDeclarations, Metrics/AbcSize, Layout/LineLength
|
|
33
33
|
public def initialize_clone(new_instance, cloneable_instance)
|
|
34
34
|
name_clone = cloneable_instance.instance_variable_get(:@name)
|
|
35
35
|
category_clone = cloneable_instance.instance_variable_get(:@category)
|
|
@@ -49,6 +49,6 @@ module SmartCore::Types::Primitive::Factory::RuntimeTypeBuilder
|
|
|
49
49
|
new_instance.instance_variable_set(:@lock_clone, lock_clone)
|
|
50
50
|
new_instance.instance_variable_set(:@nilable, nilable_clone)
|
|
51
51
|
end
|
|
52
|
-
# rubocop:enable Metrics/AbcSize, Layout/LineLength
|
|
52
|
+
# rubocop:enable Style/AccessModifierDeclarations, Metrics/AbcSize, Layout/LineLength
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -49,7 +49,7 @@ class SmartCore::Types::Primitive::InvariantControl::Chain::Result
|
|
|
49
49
|
# @api private
|
|
50
50
|
# @since 0.1.0
|
|
51
51
|
def error_codes
|
|
52
|
-
invariant_results.select(&:failure?).map do |invariant_result|
|
|
52
|
+
invariant_results.select(&:failure?).map! do |invariant_result|
|
|
53
53
|
"#{invariant_chain.name}.#{invariant_result.invariant.name}".tap(&:freeze)
|
|
54
54
|
end
|
|
55
55
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.2.0
|
|
5
|
-
# @version 0.
|
|
5
|
+
# @version 0.8.0
|
|
6
6
|
class SmartCore::Types::Primitive::InvariantControl::Chain
|
|
7
7
|
require_relative 'chain/result'
|
|
8
8
|
|
|
@@ -51,6 +51,18 @@ class SmartCore::Types::Primitive::InvariantControl::Chain
|
|
|
51
51
|
)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
# @param value [Any]
|
|
55
|
+
# @param runtime_attributes [Array<Any>]
|
|
56
|
+
# @return [Boolean]
|
|
57
|
+
#
|
|
58
|
+
# @api private
|
|
59
|
+
# @since 0.8.0
|
|
60
|
+
def simply_check(value, runtime_attributes)
|
|
61
|
+
(invariants.any? do |invariant|
|
|
62
|
+
invariant.simply_check(value, runtime_attributes) == false
|
|
63
|
+
end) ? false : true
|
|
64
|
+
end
|
|
65
|
+
|
|
54
66
|
private
|
|
55
67
|
|
|
56
68
|
# @return [Array<SmartCore::Types::Primitive::InvariantControl::Single>]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.2.0
|
|
5
|
-
# @version 0.
|
|
5
|
+
# @version 0.8.0
|
|
6
6
|
class SmartCore::Types::Primitive::InvariantControl::Single
|
|
7
7
|
require_relative 'single/result'
|
|
8
8
|
|
|
@@ -47,6 +47,16 @@ class SmartCore::Types::Primitive::InvariantControl::Single
|
|
|
47
47
|
Result.new(self, value, validation_result)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
# @param value [Any]
|
|
51
|
+
# @param runtime_attributes [Array<Any>]
|
|
52
|
+
# @return [Boolean]
|
|
53
|
+
#
|
|
54
|
+
# @api private
|
|
55
|
+
# @since 0.8.0
|
|
56
|
+
def simply_check(value, runtime_attributes)
|
|
57
|
+
!!invariant_checker.call(value, runtime_attributes)
|
|
58
|
+
end
|
|
59
|
+
|
|
50
60
|
private
|
|
51
61
|
|
|
52
62
|
# @return [Proc]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.2.0
|
|
5
|
-
# @version 0.
|
|
5
|
+
# @version 0.8.0
|
|
6
6
|
class SmartCore::Types::Primitive::InvariantControl
|
|
7
7
|
require_relative 'invariant_control/result'
|
|
8
8
|
require_relative 'invariant_control/single'
|
|
@@ -27,9 +27,13 @@ class SmartCore::Types::Primitive::InvariantControl
|
|
|
27
27
|
#
|
|
28
28
|
# @api private
|
|
29
29
|
# @since 0.2.0
|
|
30
|
+
# @version 0.8.1
|
|
30
31
|
def initialize(invariant_chains, invariants)
|
|
31
32
|
@invariant_chains = invariant_chains
|
|
32
33
|
@invariants = invariants
|
|
34
|
+
# NOTE: most types define only a checker (no invariants); precompute the
|
|
35
|
+
# empty-case so #simply_check can short-circuit on the hot validation path.
|
|
36
|
+
@no_invariants = invariant_chains.empty? && invariants.empty?
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
# @param value [Any]
|
|
@@ -51,6 +55,27 @@ class SmartCore::Types::Primitive::InvariantControl
|
|
|
51
55
|
end
|
|
52
56
|
end
|
|
53
57
|
|
|
58
|
+
# @param value [Any]
|
|
59
|
+
# @param runtime_attributes [Array<Any>]
|
|
60
|
+
# @return [Boolean]
|
|
61
|
+
#
|
|
62
|
+
# @api private
|
|
63
|
+
# @since 0.8.0
|
|
64
|
+
# @version 0.8.1
|
|
65
|
+
def simply_check(value, runtime_attributes)
|
|
66
|
+
return true if @no_invariants
|
|
67
|
+
|
|
68
|
+
return false if invariant_chains.any? do |chain|
|
|
69
|
+
chain.simply_check(value, runtime_attributes) == false
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
return false if invariants.any? do |invariant|
|
|
73
|
+
invariant.simply_check(value, runtime_attributes) == false
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
true
|
|
77
|
+
end
|
|
78
|
+
|
|
54
79
|
private
|
|
55
80
|
|
|
56
81
|
# @return [Array<SmartCore::Types::Primitive::InvariantControl::Chain>]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.2.0
|
|
5
|
-
# @version 0.
|
|
5
|
+
# @version 0.8.0
|
|
6
6
|
class SmartCore::Types::Primitive::Validator
|
|
7
7
|
require_relative 'validator/result'
|
|
8
8
|
|
|
@@ -61,8 +61,11 @@ class SmartCore::Types::Primitive::Validator
|
|
|
61
61
|
#
|
|
62
62
|
# @api private
|
|
63
63
|
# @since 0.2.0
|
|
64
|
+
# @version 0.8.1
|
|
64
65
|
def valid?(value)
|
|
65
|
-
|
|
66
|
+
runtime_attributes = type.runtime_attributes
|
|
67
|
+
return false unless type_checker.call(value, runtime_attributes) # => Boolean
|
|
68
|
+
invariant_control.simply_check(value, runtime_attributes) # => Boolean
|
|
66
69
|
end
|
|
67
70
|
|
|
68
71
|
# @param value [Any]
|
|
@@ -70,11 +73,12 @@ class SmartCore::Types::Primitive::Validator
|
|
|
70
73
|
#
|
|
71
74
|
# @api private
|
|
72
75
|
# @since 0.2.0
|
|
73
|
-
# @version 0.
|
|
76
|
+
# @version 0.8.1
|
|
74
77
|
def validate(value)
|
|
75
|
-
|
|
78
|
+
runtime_attributes = type.runtime_attributes
|
|
79
|
+
checker_result = type_checker.call(value, runtime_attributes) # => Boolean
|
|
76
80
|
return Result.new(type, value, checker_result) unless checker_result
|
|
77
|
-
invariant_result = invariant_control.check(value,
|
|
81
|
+
invariant_result = invariant_control.check(value, runtime_attributes)
|
|
78
82
|
invariant_errors = invariant_result.invariant_errors.map { |error| "#{type.name}.#{error}" }
|
|
79
83
|
Result.new(type, value, checker_result, invariant_errors)
|
|
80
84
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
using SmartCore::Ext::BasicObjectAsObject
|
|
4
|
+
|
|
3
5
|
# @api public
|
|
4
|
-
# @since 0.
|
|
6
|
+
# @since 0.8.0
|
|
5
7
|
SmartCore::Types::Value.define_type(:Method) do |type|
|
|
6
8
|
type.define_checker do |value|
|
|
7
|
-
|
|
9
|
+
value.is_a?(::Method)
|
|
8
10
|
end
|
|
9
11
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
using SmartCore::Ext::BasicObjectAsObject
|
|
4
|
+
|
|
3
5
|
# @api public
|
|
4
|
-
# @since 0.
|
|
6
|
+
# @since 0.9.0
|
|
5
7
|
SmartCore::Types::Value.define_type(:Range) do |type|
|
|
6
8
|
type.define_checker do |value|
|
|
7
|
-
|
|
9
|
+
value.is_a?(::Range)
|
|
8
10
|
end
|
|
9
11
|
end
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
using SmartCore::Ext::BasicObjectAsObject
|
|
4
|
+
|
|
3
5
|
# @api public
|
|
4
|
-
# @since 0.
|
|
6
|
+
# @since 0.9.0
|
|
5
7
|
SmartCore::Types::Value.define_type(:Rational) do |type|
|
|
6
8
|
type.define_checker do |value|
|
|
7
|
-
|
|
9
|
+
value.is_a?(::Rational)
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
type.define_caster do |value|
|
|
11
|
-
|
|
13
|
+
::Kernel.Rational(value)
|
|
14
|
+
rescue ::TypeError, ::FloatDomainError
|
|
15
|
+
# NOTE: FloatDomainError is raised when you try to type cast Float::INFINITY or Float::NAN
|
|
16
|
+
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Rational')
|
|
12
17
|
end
|
|
13
18
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
using SmartCore::Ext::BasicObjectAsObject
|
|
4
|
+
|
|
3
5
|
# @api public
|
|
4
|
-
# @since 0.
|
|
6
|
+
# @since 0.9.0
|
|
5
7
|
SmartCore::Types::Value.define_type(:UnboundMethod) do |type|
|
|
6
8
|
type.define_checker do |value|
|
|
7
|
-
|
|
9
|
+
value.is_a?(::UnboundMethod)
|
|
8
10
|
end
|
|
9
11
|
end
|
data/smart_types.gemspec
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require_relative 'lib/smart_core/types/version'
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
|
-
spec.required_ruby_version = Gem::Requirement.new('>=
|
|
6
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.0')
|
|
7
7
|
|
|
8
8
|
spec.name = 'smart_types'
|
|
9
9
|
spec.version = SmartCore::Types::VERSION
|
|
@@ -32,13 +32,13 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
33
|
spec.require_paths = ['lib']
|
|
34
34
|
|
|
35
|
-
spec.add_dependency 'smart_engine', '~> 0.
|
|
35
|
+
spec.add_dependency 'smart_engine', '~> 0.17'
|
|
36
36
|
|
|
37
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
|
37
|
+
spec.add_development_dependency 'bundler', '~> 2.4'
|
|
38
38
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
39
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
|
40
|
-
spec.add_development_dependency 'armitage-rubocop', '~> 1.
|
|
41
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.12'
|
|
40
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 1.51'
|
|
41
|
+
spec.add_development_dependency 'simplecov', '~> 0.22'
|
|
42
42
|
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
|
|
43
|
-
spec.add_development_dependency 'pry', '~> 0.
|
|
43
|
+
spec.add_development_dependency 'pry', '~> 0.14'
|
|
44
44
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smart_types
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rustam Ibragimov
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: smart_engine
|
|
@@ -16,28 +15,28 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0.
|
|
18
|
+
version: '0.17'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0.
|
|
25
|
+
version: '0.17'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: bundler
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
30
|
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '2.
|
|
32
|
+
version: '2.4'
|
|
34
33
|
type: :development
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
37
|
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '2.
|
|
39
|
+
version: '2.4'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
41
|
name: rake
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -58,42 +57,42 @@ dependencies:
|
|
|
58
57
|
requirements:
|
|
59
58
|
- - "~>"
|
|
60
59
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '3.
|
|
60
|
+
version: '3.12'
|
|
62
61
|
type: :development
|
|
63
62
|
prerelease: false
|
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
64
|
requirements:
|
|
66
65
|
- - "~>"
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '3.
|
|
67
|
+
version: '3.12'
|
|
69
68
|
- !ruby/object:Gem::Dependency
|
|
70
69
|
name: armitage-rubocop
|
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
72
|
- - "~>"
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '1.
|
|
74
|
+
version: '1.51'
|
|
76
75
|
type: :development
|
|
77
76
|
prerelease: false
|
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
78
|
requirements:
|
|
80
79
|
- - "~>"
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '1.
|
|
81
|
+
version: '1.51'
|
|
83
82
|
- !ruby/object:Gem::Dependency
|
|
84
83
|
name: simplecov
|
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
|
86
85
|
requirements:
|
|
87
86
|
- - "~>"
|
|
88
87
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0.
|
|
88
|
+
version: '0.22'
|
|
90
89
|
type: :development
|
|
91
90
|
prerelease: false
|
|
92
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
92
|
requirements:
|
|
94
93
|
- - "~>"
|
|
95
94
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0.
|
|
95
|
+
version: '0.22'
|
|
97
96
|
- !ruby/object:Gem::Dependency
|
|
98
97
|
name: simplecov-lcov
|
|
99
98
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -114,14 +113,14 @@ dependencies:
|
|
|
114
113
|
requirements:
|
|
115
114
|
- - "~>"
|
|
116
115
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: '0.
|
|
116
|
+
version: '0.14'
|
|
118
117
|
type: :development
|
|
119
118
|
prerelease: false
|
|
120
119
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
120
|
requirements:
|
|
122
121
|
- - "~>"
|
|
123
122
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: '0.
|
|
123
|
+
version: '0.14'
|
|
125
124
|
description: |
|
|
126
125
|
Full-featured type system for any ruby project. Supports custom type definition,
|
|
127
126
|
type validation, type casting and type categorizing. Provides a set of commonly used type
|
|
@@ -224,7 +223,6 @@ metadata:
|
|
|
224
223
|
homepage_uri: https://github.com/smart-rb/smart_types
|
|
225
224
|
source_code_uri: https://github.com/smart-rb/smart_types
|
|
226
225
|
changelog_uri: https://github.com/smart-rb/smart_types/blob/master/CHANGELOG.md
|
|
227
|
-
post_install_message:
|
|
228
226
|
rdoc_options: []
|
|
229
227
|
require_paths:
|
|
230
228
|
- lib
|
|
@@ -232,15 +230,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
232
230
|
requirements:
|
|
233
231
|
- - ">="
|
|
234
232
|
- !ruby/object:Gem::Version
|
|
235
|
-
version:
|
|
233
|
+
version: '3.0'
|
|
236
234
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
235
|
requirements:
|
|
238
236
|
- - ">="
|
|
239
237
|
- !ruby/object:Gem::Version
|
|
240
238
|
version: '0'
|
|
241
239
|
requirements: []
|
|
242
|
-
rubygems_version: 3.
|
|
243
|
-
signing_key:
|
|
240
|
+
rubygems_version: 3.6.9
|
|
244
241
|
specification_version: 4
|
|
245
242
|
summary: Full-featured type system for any ruby project.
|
|
246
243
|
test_files: []
|