smart_types 0.7.1 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 272f5a15bb76008e456d87ad711a534518fa746369c3c64b8915f09265f75fea
4
- data.tar.gz: 53ccc4912ec1577133ccfbe678dba4741a85c5a8521b72f2fca396823c31797d
3
+ metadata.gz: 1b592f16e69b2b34662ca1ff8199a5fc0e4ae7234fb47288df3e41444a53c214
4
+ data.tar.gz: 7f1ff6580098205bb9e4b5295eff21e4ced1173a73e4e967bdd5f4997e398377
5
5
  SHA512:
6
- metadata.gz: 1bb710c2e0f11a8a267a2663fcb9ad75b60352d306b17a8bebad812013531ea1ee7fac4996bc342be245ac09939d862ca0f2dc2a4c26dfd5c9aa064ea41b270f
7
- data.tar.gz: a2d03bcc580625b3af5ffe9535cd5b26e972b4d4b6189d71aceaa09c48f527cb2310c8aa68238803093357dee4f8b43817d3b95ddd5c912bd11dc9a6da2bbdf8
6
+ metadata.gz: 1b3c4a74168dcfcdf3f85f9baa9f3a66e0c95d0b2cf726a4f9b2ec711cf5f127dd0e060e322369780178ed7d3fe2efc708d31458c9099b2eee5ef1746a72eddc
7
+ data.tar.gz: 9beb0d346cc40c8f2ce8233c448306d51aa5b771e1473b358c7650e1238813e8c9115bdc66d8e1409900642baf854f6f4a9de2b51faf968351cd924972156f59
@@ -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
@@ -22,3 +22,7 @@ Style/RedundantBegin:
22
22
  # NOTE: used only in specs and it is ok in specs
23
23
  Lint/EmptyBlock:
24
24
  Enabled: false
25
+
26
+ # NOTE: too situative and too subjective
27
+ Naming/VariableNumber:
28
+ Enabled: false
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
- - (**TruffelRuby** fix) Fixed `NoMethodError: private method 'initialize_clone'` failing on type object duplication and cloning (`#dup` and `#clone`).
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.7.1)
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 (6.1.1)
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
- zeitwerk (~> 2.3)
16
- armitage-rubocop (1.7.0.1)
17
- rubocop (= 1.7.0)
18
- rubocop-performance (= 1.9.1)
19
- rubocop-rails (= 2.9.1)
20
- rubocop-rake (= 0.5.1)
21
- rubocop-rspec (= 2.1.0)
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.7)
25
- diff-lcs (1.4.4)
26
- docile (1.3.5)
27
- i18n (1.8.7)
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.14.3)
31
- parallel (1.20.1)
32
- parser (3.0.0.0)
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.13.1)
36
+ pry (0.14.1)
35
37
  coderay (~> 1.1)
36
38
  method_source (~> 1.0)
37
- rack (2.2.3)
38
- rainbow (3.0.0)
39
- rake (13.0.3)
40
- regexp_parser (2.0.3)
41
- rexml (3.2.4)
42
- rspec (3.10.0)
43
- rspec-core (~> 3.10.0)
44
- rspec-expectations (~> 3.10.0)
45
- rspec-mocks (~> 3.10.0)
46
- rspec-core (3.10.1)
47
- rspec-support (~> 3.10.0)
48
- rspec-expectations (3.10.1)
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.10.0)
51
- rspec-mocks (3.10.1)
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.10.0)
54
- rspec-support (3.10.1)
55
- rubocop (1.7.0)
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.7.1.5)
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.2.0, < 2.0)
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, < 2.0)
64
- rubocop-ast (1.4.0)
65
- parser (>= 2.7.1.5)
66
- rubocop-performance (1.9.1)
67
- rubocop (>= 0.90.0, < 2.0)
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.9.1)
76
+ rubocop-rails (2.16.1)
70
77
  activesupport (>= 4.2.0)
71
78
  rack (>= 1.1)
72
- rubocop (>= 0.90.0, < 2.0)
73
- rubocop-rake (0.5.1)
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
- rubocop-ast (>= 1.1.0)
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.2)
86
- smart_engine (0.12.0)
87
- tzinfo (2.0.4)
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 (1.7.0)
90
- zeitwerk (2.4.2)
97
+ unicode-display_width (2.3.0)
91
98
 
92
99
  PLATFORMS
93
100
  arm64-darwin-21
94
- x86_64-darwin-19
95
- x86_64-darwin-20
96
- x86_64-darwin-21
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.2.31
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.3.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.3.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.3.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>]
@@ -34,7 +34,7 @@ class SmartCore::Types::Primitive::NilableValidator
34
34
  # @api private
35
35
  # @since 0.2.0
36
36
  def valid?(value)
37
- value == nil ? true : validator.valid?(value)
37
+ (value == nil) ? true : validator.valid?(value)
38
38
  end
39
39
 
40
40
  # @param value [Any]
@@ -2,7 +2,7 @@
2
2
 
3
3
  # @api private
4
4
  # @since 0.2.0
5
- # @version 0.3.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
- validate(value).success?
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.x.0
6
+ # @since 0.8.0
5
7
  SmartCore::Types::Value.define_type(:Method) do |type|
6
8
  type.define_checker do |value|
7
- # TODO: realize
9
+ value.is_a?(::Method)
8
10
  end
9
11
  end
@@ -6,7 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- # @version 0.7.1
10
- VERSION = '0.7.1'
9
+ # @version 0.8.0
10
+ VERSION = '0.8.0'
11
11
  end
12
12
  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.4.10')
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.7.1
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-08-31 00:00:00.000000000 Z
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.4.10
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.11
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.