smart_types 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +14 -5
- data/Gemfile.lock +65 -58
- data/README.md +20 -1
- 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 +19 -1
- data/lib/smart_core/types/primitive/nilable_validator.rb +1 -1
- data/lib/smart_core/types/primitive/validator.rb +5 -2
- data/lib/smart_core/types/value/method.rb +4 -2
- data/lib/smart_core/types/version.rb +2 -2
- data/smart_types.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b592f16e69b2b34662ca1ff8199a5fc0e4ae7234fb47288df3e41444a53c214
|
4
|
+
data.tar.gz: 7f1ff6580098205bb9e4b5295eff21e4ced1173a73e4e967bdd5f4997e398377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b3c4a74168dcfcdf3f85f9baa9f3a66e0c95d0b2cf726a4f9b2ec711cf5f127dd0e060e322369780178ed7d3fe2efc708d31458c9099b2eee5ef1746a72eddc
|
7
|
+
data.tar.gz: 9beb0d346cc40c8f2ce8233c448306d51aa5b771e1473b358c7650e1238813e8c9115bdc66d8e1409900642baf854f6f4a9de2b51faf968351cd924972156f59
|
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,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
# [0.8.0] - 2022-11-25
|
5
|
+
### Added
|
6
|
+
- New types of `SmartCore::Types::Value` category:
|
7
|
+
- `SmartCore::Types::Value::Method`
|
8
|
+
- Support for *Ruby@3.1*;
|
9
|
+
### Changed
|
10
|
+
- `SmartCore::Types::Primitive#valid?` now has no dependency on invariant control result object interface
|
11
|
+
(reduced object allocation count during validation: move from OOP-style to Procedure-style inside boolean methods);
|
12
|
+
- Updated development dependencies (see `Gemfile.lock` diffs);
|
13
|
+
- Support for *Ruby@2.4*, *Ruby@2.5* and *Ruby@2.6* has ended;
|
14
|
+
|
4
15
|
# [0.7.1] - 2022-08-31
|
5
16
|
### Fixed
|
6
|
-
-
|
7
|
-
`TruffleRuby` implementation makes `initialize_clone` method private by default even if your manually defined method is implicitly public
|
17
|
+
- **TruffelRuby**: fixed `NoMethodError: private method 'initialize_clone'` failing on type object duplication and cloning (`#dup` and `#clone`).
|
18
|
+
`TruffleRuby` implementation makes `initialize_clone` method private by default even if your manually defined method is implicitly public
|
19
|
+
(see `SmartCore::Types::Primitive::Factory::RuntimeTypeBuilder.initialize_clone` and `SmartCore::Types::Primitive#initialize_copy`).
|
8
20
|
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
21
|
|
13
22
|
# [0.7.0] - 2021-11-22
|
14
23
|
### Added
|
data/Gemfile.lock
CHANGED
@@ -1,80 +1,86 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart_types (0.
|
4
|
+
smart_types (0.8.0)
|
5
5
|
smart_engine (~> 0.11)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (
|
10
|
+
activesupport (7.0.4)
|
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 (= 1.
|
18
|
-
rubocop-
|
19
|
-
rubocop-
|
20
|
-
rubocop-
|
21
|
-
|
22
|
-
ast (2.4.1)
|
15
|
+
armitage-rubocop (1.36.0)
|
16
|
+
rubocop (= 1.36.0)
|
17
|
+
rubocop-performance (= 1.15.0)
|
18
|
+
rubocop-rails (= 2.16.1)
|
19
|
+
rubocop-rake (= 0.6.0)
|
20
|
+
rubocop-rspec (= 2.13.2)
|
21
|
+
ast (2.4.2)
|
23
22
|
coderay (1.1.3)
|
24
|
-
concurrent-ruby (1.1.
|
25
|
-
diff-lcs (1.
|
26
|
-
docile (1.
|
27
|
-
|
23
|
+
concurrent-ruby (1.1.10)
|
24
|
+
diff-lcs (1.5.0)
|
25
|
+
docile (1.4.0)
|
26
|
+
ffi (1.15.5-java)
|
27
|
+
i18n (1.12.0)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
|
+
json (2.6.2)
|
30
|
+
json (2.6.2-java)
|
29
31
|
method_source (1.0.0)
|
30
|
-
minitest (5.
|
31
|
-
parallel (1.
|
32
|
-
parser (3.
|
32
|
+
minitest (5.16.3)
|
33
|
+
parallel (1.22.1)
|
34
|
+
parser (3.1.2.1)
|
33
35
|
ast (~> 2.4.1)
|
34
|
-
pry (0.
|
36
|
+
pry (0.14.1)
|
35
37
|
coderay (~> 1.1)
|
36
38
|
method_source (~> 1.0)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
rspec
|
47
|
-
rspec-
|
48
|
-
|
39
|
+
pry (0.14.1-java)
|
40
|
+
coderay (~> 1.1)
|
41
|
+
method_source (~> 1.0)
|
42
|
+
spoon (~> 0.0)
|
43
|
+
rack (3.0.1)
|
44
|
+
rainbow (3.1.1)
|
45
|
+
rake (13.0.6)
|
46
|
+
regexp_parser (2.6.1)
|
47
|
+
rexml (3.2.5)
|
48
|
+
rspec (3.12.0)
|
49
|
+
rspec-core (~> 3.12.0)
|
50
|
+
rspec-expectations (~> 3.12.0)
|
51
|
+
rspec-mocks (~> 3.12.0)
|
52
|
+
rspec-core (3.12.0)
|
53
|
+
rspec-support (~> 3.12.0)
|
54
|
+
rspec-expectations (3.12.0)
|
49
55
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-mocks (3.
|
56
|
+
rspec-support (~> 3.12.0)
|
57
|
+
rspec-mocks (3.12.0)
|
52
58
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.
|
54
|
-
rspec-support (3.
|
55
|
-
rubocop (1.
|
59
|
+
rspec-support (~> 3.12.0)
|
60
|
+
rspec-support (3.12.0)
|
61
|
+
rubocop (1.36.0)
|
62
|
+
json (~> 2.3)
|
56
63
|
parallel (~> 1.10)
|
57
|
-
parser (>= 2.
|
64
|
+
parser (>= 3.1.2.1)
|
58
65
|
rainbow (>= 2.2.2, < 4.0)
|
59
66
|
regexp_parser (>= 1.8, < 3.0)
|
60
|
-
rexml
|
61
|
-
rubocop-ast (>= 1.
|
67
|
+
rexml (>= 3.2.5, < 4.0)
|
68
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
62
69
|
ruby-progressbar (~> 1.7)
|
63
|
-
unicode-display_width (>= 1.4.0, <
|
64
|
-
rubocop-ast (1.
|
65
|
-
parser (>=
|
66
|
-
rubocop-performance (1.
|
67
|
-
rubocop (>=
|
70
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
71
|
+
rubocop-ast (1.23.0)
|
72
|
+
parser (>= 3.1.1.0)
|
73
|
+
rubocop-performance (1.15.0)
|
74
|
+
rubocop (>= 1.7.0, < 2.0)
|
68
75
|
rubocop-ast (>= 0.4.0)
|
69
|
-
rubocop-rails (2.
|
76
|
+
rubocop-rails (2.16.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
|
-
|
82
|
+
rubocop-rspec (2.13.2)
|
83
|
+
rubocop (~> 1.33)
|
78
84
|
ruby-progressbar (1.11.0)
|
79
85
|
simplecov (0.21.2)
|
80
86
|
docile (~> 1.1)
|
@@ -82,18 +88,19 @@ GEM
|
|
82
88
|
simplecov_json_formatter (~> 0.1)
|
83
89
|
simplecov-html (0.12.3)
|
84
90
|
simplecov-lcov (0.8.0)
|
85
|
-
simplecov_json_formatter (0.1.
|
86
|
-
smart_engine (0.
|
87
|
-
|
91
|
+
simplecov_json_formatter (0.1.4)
|
92
|
+
smart_engine (0.17.0)
|
93
|
+
spoon (0.0.6)
|
94
|
+
ffi
|
95
|
+
tzinfo (2.0.5)
|
88
96
|
concurrent-ruby (~> 1.0)
|
89
|
-
unicode-display_width (
|
90
|
-
zeitwerk (2.4.2)
|
97
|
+
unicode-display_width (2.3.0)
|
91
98
|
|
92
99
|
PLATFORMS
|
93
100
|
arm64-darwin-21
|
94
|
-
|
95
|
-
|
96
|
-
x86_64-
|
101
|
+
ruby
|
102
|
+
universal-java-11
|
103
|
+
x86_64-linux
|
97
104
|
|
98
105
|
DEPENDENCIES
|
99
106
|
armitage-rubocop (~> 1.7)
|
@@ -106,4 +113,4 @@ DEPENDENCIES
|
|
106
113
|
smart_types!
|
107
114
|
|
108
115
|
BUNDLED WITH
|
109
|
-
2.
|
116
|
+
2.3.17
|
data/README.md
CHANGED
@@ -108,6 +108,7 @@ SmartCore::Types::Value::Time
|
|
108
108
|
SmartCore::Types::Value::DateTime
|
109
109
|
SmartCore::Types::Value::Date
|
110
110
|
SmartCore::Types::Value::TimeBased
|
111
|
+
SmartCore::Types::Value::Method
|
111
112
|
```
|
112
113
|
|
113
114
|
---
|
@@ -495,10 +496,16 @@ end
|
|
495
496
|
SmartCore::Types::Value::Date.cast('2020-01-01', { iso: :rfc3339 })
|
496
497
|
```
|
497
498
|
|
499
|
+
- custom type categories (an ability to register your own type category)
|
500
|
+
|
501
|
+
```ruby
|
502
|
+
SmartCore::Types.define_category(:YourCategoryName)
|
503
|
+
SmartCore::Types::YourCategoryName.define_type(:YourNewType) { ... }
|
504
|
+
```
|
505
|
+
|
498
506
|
- new types:
|
499
507
|
|
500
508
|
```ruby
|
501
|
-
SmartCore::Types::Value::Method
|
502
509
|
SmartCore::Types::Value::UnboundMethod
|
503
510
|
SmartCore::Types::Value::Enumerable
|
504
511
|
SmartCore::Types::Value::Comparable
|
@@ -525,6 +532,18 @@ SmartCore::Types::Behavior::Truthy
|
|
525
532
|
SmartCore::Types::Behavior::Falsy
|
526
533
|
```
|
527
534
|
|
535
|
+
```ruby
|
536
|
+
# Common types:
|
537
|
+
SmartCore::Types::Common::UUDv4
|
538
|
+
```
|
539
|
+
|
540
|
+
```ruby
|
541
|
+
# think about:
|
542
|
+
Clonable # for example, you can not clone or duplicate Method-objects
|
543
|
+
Duplicable
|
544
|
+
Allocatable # for example, Method object can not be allocated with #allocate method
|
545
|
+
```
|
546
|
+
|
528
547
|
- `#sum` alias for `|` and `#mult` alias for `&` (with a support for type name definition and other API);
|
529
548
|
|
530
549
|
- 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'
|
@@ -51,6 +51,24 @@ class SmartCore::Types::Primitive::InvariantControl
|
|
51
51
|
end
|
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
|
+
return false if invariant_chains.any? do |chain|
|
62
|
+
chain.simply_check(value, runtime_attributes) == false
|
63
|
+
end
|
64
|
+
|
65
|
+
return false if invariants.any? do |invariant|
|
66
|
+
invariant.simply_check(value, runtime_attributes) == false
|
67
|
+
end
|
68
|
+
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
54
72
|
private
|
55
73
|
|
56
74
|
# @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.0
|
64
65
|
def valid?(value)
|
65
|
-
|
66
|
+
return false unless type_checker.call(value, type.runtime_attributes) # => Boolean
|
67
|
+
return false unless invariant_control.simply_check(value, type.runtime_attributes) # => Boolean
|
68
|
+
true
|
66
69
|
end
|
67
70
|
|
68
71
|
# @param value [Any]
|
@@ -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
|
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('>= 2.
|
6
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7')
|
7
7
|
|
8
8
|
spec.name = 'smart_types'
|
9
9
|
spec.version = SmartCore::Types::VERSION
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_engine
|
@@ -232,14 +232,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
232
232
|
requirements:
|
233
233
|
- - ">="
|
234
234
|
- !ruby/object:Gem::Version
|
235
|
-
version: 2.
|
235
|
+
version: '2.7'
|
236
236
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
237
|
requirements:
|
238
238
|
- - ">="
|
239
239
|
- !ruby/object:Gem::Version
|
240
240
|
version: '0'
|
241
241
|
requirements: []
|
242
|
-
rubygems_version: 3.3.
|
242
|
+
rubygems_version: 3.3.7
|
243
243
|
signing_key:
|
244
244
|
specification_version: 4
|
245
245
|
summary: Full-featured type system for any ruby project.
|