smart_types 0.6.0 → 0.7.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 +52 -0
- data/CHANGELOG.md +9 -4
- data/Gemfile.lock +5 -2
- data/README.md +17 -17
- data/lib/smart_core/types/primitive/factory.rb +1 -1
- data/lib/smart_core/types/value/date.rb +2 -2
- data/lib/smart_core/types/value/date_time.rb +2 -2
- data/lib/smart_core/types/version.rb +2 -2
- data/smart_types.gemspec +2 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5af5b9faba15b86a36c7020e9c4c669973f2e443e0e490cfbfee7805f6b6ce7
|
4
|
+
data.tar.gz: 709095db933eaf28c51c28872ad8cc24bf97636099c36a6d9d40378d22fecf94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '092648864bbbd340c93b146eed7c59044d85065ac4220626130d576a3a8846f9039f88e0c20ce6f1e40811f1d788c42ea5703e81fd635026ebd3ab30606ecf52'
|
7
|
+
data.tar.gz: baa24e784f8e6e7745f9ff9662fed3e905bcaf6842ce4ef02464fd7a82a6768cd6641d425cbf531683a981006b452b8811331633de5a8cf613891c97a25a1b28
|
@@ -0,0 +1,52 @@
|
|
1
|
+
name: ci
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
ci:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
ruby:
|
19
|
+
- version: 2.5
|
20
|
+
continue-on-error: false
|
21
|
+
- version: 2.6
|
22
|
+
continue-on-error: false
|
23
|
+
- version: 2.7
|
24
|
+
continue-on-error: false
|
25
|
+
- version: 3.0
|
26
|
+
continue-on-error: false
|
27
|
+
- version: ruby-head
|
28
|
+
continue-on-error: true
|
29
|
+
- version: jruby-head
|
30
|
+
continue-on-error: true
|
31
|
+
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v2
|
34
|
+
- name: Set up Ruby
|
35
|
+
uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
bundler-cache: true
|
38
|
+
ruby-version: ${{ matrix.ruby.version }}
|
39
|
+
- name: Install dependencies
|
40
|
+
run: bundle install
|
41
|
+
continue-on-error: ${{ matrix.ruby.continue-on-error }}
|
42
|
+
- name: Run rubocop
|
43
|
+
run: bundle exec rubocop
|
44
|
+
continue-on-error: ${{ matrix.ruby.continue-on-error }}
|
45
|
+
- name: Run specs
|
46
|
+
run: bundle exec rspec
|
47
|
+
continue-on-error: ${{ matrix.ruby.continue-on-error }}
|
48
|
+
- name: Coveralls
|
49
|
+
uses: coverallsapp/github-action@master
|
50
|
+
continue-on-error: true
|
51
|
+
with:
|
52
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
# [0.7.0] - 2021-11-22
|
5
|
+
### Added
|
6
|
+
- Added Github Actions CI;
|
7
|
+
- Use `ArgumentError` instead of `DateError` in related type-casters;
|
8
|
+
- Fix typos in documentation;
|
9
|
+
|
4
10
|
# [0.6.0] - 2021-04-29
|
5
11
|
### Added
|
6
12
|
- New type of `SmartCode::Types::Variadic` category:
|
7
13
|
- `SmartCore::Types::Variadic::ArrayOf` (`Array` with element types validation)
|
8
14
|
|
9
|
-
|
10
15
|
# [0.5.0] - 2021-01-28
|
11
16
|
### Added
|
12
17
|
- New types of `SmartCore::Types::Variadic` category:
|
@@ -20,7 +25,7 @@ All notable changes to this project will be documented in this file.
|
|
20
25
|
### Added
|
21
26
|
- Extended **Type Definition API**: support for **runtime attributes**:
|
22
27
|
- Type checkers, type casters and type invariants now receives runtime attributes (you can omit these);
|
23
|
-
- Type
|
28
|
+
- Type definition extended with `runtime_attribute_checker`-checker definition (runtime attributes validator);
|
24
29
|
- Types with incorrect runtime attributes will raise `SmartCore::Types::IncorrectRuntimeAttributesError` exception;
|
25
30
|
- Types which has no support for runtime attributes will raise `SmartCore::Types::RuntimeAttributesUnsupportedError` excpetion;
|
26
31
|
- All types by default has a method alias (`()`) which does not allow runtime attributes (for example: `SmartCore::Types::Value::String` has
|
@@ -44,9 +49,9 @@ All notable changes to this project will be documented in this file.
|
|
44
49
|
## [0.2.0] - 2020-11-21
|
45
50
|
### Added
|
46
51
|
- Brand new **Type invariant API**:
|
47
|
-
- globally refactored validation logic (with backward
|
52
|
+
- globally refactored validation logic (with backward compatibility for `#valid?(value)` method);
|
48
53
|
- new type definition DSL: `.invariant(name)` and `.invariant_chain(name)`;
|
49
|
-
- chained invariants will be invoked according to the definition order (second
|
54
|
+
- chained invariants will be invoked according to the definition order (second invocation
|
50
55
|
depends on previous successful invariant check);
|
51
56
|
- new validation API: `validate(value)` (with `#errors` support based on invariant names);
|
52
57
|
- at this moment Invariant API is supported only by primitive types (type sum and type multiplication support coming soon);
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart_types (0.
|
4
|
+
smart_types (0.7.0)
|
5
5
|
smart_engine (~> 0.11)
|
6
6
|
|
7
7
|
GEM
|
@@ -81,6 +81,7 @@ GEM
|
|
81
81
|
simplecov-html (~> 0.11)
|
82
82
|
simplecov_json_formatter (~> 0.1)
|
83
83
|
simplecov-html (0.12.3)
|
84
|
+
simplecov-lcov (0.8.0)
|
84
85
|
simplecov_json_formatter (0.1.2)
|
85
86
|
smart_engine (0.11.0)
|
86
87
|
tzinfo (2.0.4)
|
@@ -91,6 +92,7 @@ GEM
|
|
91
92
|
PLATFORMS
|
92
93
|
x86_64-darwin-19
|
93
94
|
x86_64-darwin-20
|
95
|
+
x86_64-darwin-21
|
94
96
|
|
95
97
|
DEPENDENCIES
|
96
98
|
armitage-rubocop (~> 1.7)
|
@@ -99,7 +101,8 @@ DEPENDENCIES
|
|
99
101
|
rake (~> 13.0)
|
100
102
|
rspec (~> 3.10)
|
101
103
|
simplecov (~> 0.21)
|
104
|
+
simplecov-lcov (~> 0.8)
|
102
105
|
smart_types!
|
103
106
|
|
104
107
|
BUNDLED WITH
|
105
|
-
2.2.
|
108
|
+
2.2.31
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# SmartCore::Types ·
|
1
|
+
# SmartCore::Types · <a target="_blank" href="https://github.com/Cado-Labs"><img src="https://github.com/Cado-Labs/cado-labs-logos/raw/main/cado_labs_badge.svg" alt="Supported by Cado Labs" style="max-width: 100%; height: 20px"></a> · [![Gem Version](https://badge.fury.io/rb/smart_types.svg)](https://badge.fury.io/rb/smart_types) ![ci](https://github.com/smart-rb/smart_types/workflows/ci/badge.svg?branch=master) [![coverage](https://coveralls.io/repos/github/smart-rb/smart_types/badge.svg?branch=master)](https://coveralls.io/github/smart-rb/smart_types?branch=master)
|
2
2
|
|
3
3
|
> A set of objects that acts like types (type checking and type casting) with a support for basic type algebra.
|
4
4
|
|
5
|
-
Minimalistic type system for any ruby project. Supports custom type
|
5
|
+
Minimalistic type system for any ruby project. Supports custom type definition,
|
6
6
|
type validation, type casting and type categorizing. Provides a set of commonly used type
|
7
7
|
categories and general purpose types. Has a flexible and simplest type definition toolchain.
|
8
8
|
|
@@ -175,9 +175,9 @@ Invariant is a custom validation block that will work as a logical value checker
|
|
175
175
|
|
176
176
|
Type invariants does not depends on each other (invariant defined out from chain does not depends on other invariants);
|
177
177
|
|
178
|
-
Invariants inside invariant chains will be invoked in order they was defined and each internal invariant depends on the valid previous
|
178
|
+
Invariants inside invariant chains will be invoked in order they was defined and each internal invariant depends on the valid previous invariant check.
|
179
179
|
|
180
|
-
**!IMPORTANT!** Type sum and type multiplication does not support invariant checking and custom invariant
|
180
|
+
**!IMPORTANT!** Type sum and type multiplication does not support invariant checking and custom invariant definition at this moment.
|
181
181
|
Type sum and type mult ignores type invariants in their validation logic (currently this functionality in development yet).
|
182
182
|
|
183
183
|
Invariant checking is a special validation layer (see [#type validation](#type-validation) readme section). Invariant error code pattern:
|
@@ -242,7 +242,7 @@ SmartCore::Types::Value.define_type(:String) do |type|
|
|
242
242
|
end
|
243
243
|
|
244
244
|
# NOTE:
|
245
|
-
# inside a chain each next invariant
|
245
|
+
# inside a chain each next invariant invocation
|
246
246
|
# depends on previous successful invariant check
|
247
247
|
end
|
248
248
|
end
|
@@ -259,14 +259,14 @@ Type validation reflects on two APIs:
|
|
259
259
|
|
260
260
|
Type invariants does not depends on each other (invariant defined out from the chain does not depends on other invariants);
|
261
261
|
|
262
|
-
Invariants inside invariant chains will be invoked in order they was defined and each internal invariant depends on the valid previous
|
262
|
+
Invariants inside invariant chains will be invoked in order they was defined and each internal invariant depends on the valid previous invariant check.
|
263
263
|
|
264
|
-
**!IMPORTANT!** Type sum and type multiplication does not support invariant checking and custom invariant
|
264
|
+
**!IMPORTANT!** Type sum and type multiplication does not support invariant checking and custom invariant definition at this moment.
|
265
265
|
Type sum and type mult ignores type invariants in their validation logic (currently this functionality in development yet).
|
266
266
|
|
267
267
|
Invariant checking is a special validation layer (see [#type validation](#type-validation) readme section) and represents a set of error codes in result object;
|
268
268
|
|
269
|
-
Type
|
269
|
+
Type validation interface:
|
270
270
|
|
271
271
|
- `valid?(value)` - validates value and returns `true` or `false`;
|
272
272
|
- returns `ture` only if the type checker returns `true` and all invariants are valid;
|
@@ -520,18 +520,18 @@ SmartCore::Types::Protocol::Callable
|
|
520
520
|
|
521
521
|
- support for type of empty non-defined type (`SmartCore::Types::Primitive::Undefined`);
|
522
522
|
- constrained types;
|
523
|
-
-
|
523
|
+
- module-based type system integration;
|
524
524
|
- constructor implementation and support;
|
525
|
-
- support for invariant checking (and custom
|
526
|
-
- to provide a type comparability and
|
525
|
+
- support for invariant checking (and custom definition) in sum-types;
|
526
|
+
- to provide a type comparability and compatibility between all passed types
|
527
527
|
you should provide `type.reconcilable { |value, *types| .... }` setting;
|
528
|
-
- `type.reconcilable` should be
|
529
|
-
- (**preliminarily**) invariants of the concrete passed type should be valid for
|
530
|
-
- support for invariant checking (and
|
531
|
-
- to provide a type comparability and
|
528
|
+
- `type.reconcilable` should be accessible for type sum and type mult definitions;
|
529
|
+
- (**preliminarily**) invariants of the concrete passed type should be valid for successful invariant check;
|
530
|
+
- support for invariant checking (and definition) in mult-types;
|
531
|
+
- to provide a type comparability and compatibility between all passed types
|
532
532
|
you should provide `type.reconcilable { |value, *types| .... }` setting;
|
533
|
-
- `type.reconcilable` should be
|
534
|
-
- (**preliminarily**) all invariants of all types should be valid for
|
533
|
+
- `type.reconcilable` should be accessible for type sum and type mult definitions;
|
534
|
+
- (**preliminarily**) all invariants of all types should be valid for successful invariant check;
|
535
535
|
|
536
536
|
## Contributing
|
537
537
|
|
@@ -47,7 +47,7 @@ class SmartCore::Types::Primitive::Factory
|
|
47
47
|
# @api private
|
48
48
|
# @since 0.1.0
|
49
49
|
def build_type_definitions(type_definition)
|
50
|
-
raise 'Type definition is not
|
50
|
+
raise 'Type definition is not provided' unless type_definition.is_a?(Proc)
|
51
51
|
SmartCore::Types::Primitive::Factory::DefinitionContext.new.tap do |context|
|
52
52
|
context.instance_eval(&type_definition)
|
53
53
|
end.tap do |context|
|
@@ -6,7 +6,7 @@ using SmartCore::Ext::BasicObjectAsObject
|
|
6
6
|
|
7
7
|
# @api public
|
8
8
|
# @since 0.1.0
|
9
|
-
# @version 0.
|
9
|
+
# @version 0.7.0
|
10
10
|
SmartCore::Types::Value.define_type(:Date) do |type|
|
11
11
|
type.define_checker do |value|
|
12
12
|
value.is_a?(::Date) || value == ::Date::Infinity
|
@@ -17,7 +17,7 @@ SmartCore::Types::Value.define_type(:Date) do |type|
|
|
17
17
|
|
18
18
|
begin
|
19
19
|
::Date.parse(value)
|
20
|
-
rescue ::
|
20
|
+
rescue ::ArgumentError, ::TypeError
|
21
21
|
raise(SmartCore::Types::TypeCastingError, 'Non-castable to Date')
|
22
22
|
end
|
23
23
|
end
|
@@ -6,7 +6,7 @@ using SmartCore::Ext::BasicObjectAsObject
|
|
6
6
|
|
7
7
|
# @api public
|
8
8
|
# @since 0.1.0
|
9
|
-
# @version 0.
|
9
|
+
# @version 0.7.0
|
10
10
|
SmartCore::Types::Value.define_type(:DateTime) do |type|
|
11
11
|
type.define_checker do |value|
|
12
12
|
value.is_a?(::DateTime) || value == ::DateTime::Infinity
|
@@ -17,7 +17,7 @@ SmartCore::Types::Value.define_type(:DateTime) do |type|
|
|
17
17
|
|
18
18
|
begin
|
19
19
|
::DateTime.parse(value)
|
20
|
-
rescue ::
|
20
|
+
rescue ::ArgumentError, ::TypeError
|
21
21
|
raise(SmartCore::Types::TypeCastingError, 'Non-castable to DateTime')
|
22
22
|
end
|
23
23
|
end
|
data/smart_types.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = 'Full-featured type system for any ruby project.'
|
14
14
|
spec.description = <<~DESCRIPTION
|
15
|
-
Full-featured type system for any ruby project. Supports custom type
|
15
|
+
Full-featured type system for any ruby project. Supports custom type definition,
|
16
16
|
type validation, type casting and type categorizing. Provides a set of commonly used type
|
17
17
|
categories and general purpose types. Has a flexible and simplest type definition toolchain.
|
18
18
|
DESCRIPTION
|
@@ -39,5 +39,6 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_development_dependency 'rspec', '~> 3.10'
|
40
40
|
spec.add_development_dependency 'armitage-rubocop', '~> 1.7'
|
41
41
|
spec.add_development_dependency 'simplecov', '~> 0.21'
|
42
|
+
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
|
42
43
|
spec.add_development_dependency 'pry', '~> 0.13'
|
43
44
|
end
|
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.7.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: 2021-
|
11
|
+
date: 2021-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_engine
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.21'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov-lcov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: pry
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,7 +123,7 @@ dependencies:
|
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0.13'
|
111
125
|
description: |
|
112
|
-
Full-featured type system for any ruby project. Supports custom type
|
126
|
+
Full-featured type system for any ruby project. Supports custom type definition,
|
113
127
|
type validation, type casting and type categorizing. Provides a set of commonly used type
|
114
128
|
categories and general purpose types. Has a flexible and simplest type definition toolchain.
|
115
129
|
email:
|
@@ -118,6 +132,7 @@ executables: []
|
|
118
132
|
extensions: []
|
119
133
|
extra_rdoc_files: []
|
120
134
|
files:
|
135
|
+
- ".github/workflows/ci.yml"
|
121
136
|
- ".gitignore"
|
122
137
|
- ".rspec"
|
123
138
|
- ".rubocop.yml"
|
@@ -224,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
239
|
- !ruby/object:Gem::Version
|
225
240
|
version: '0'
|
226
241
|
requirements: []
|
227
|
-
rubygems_version: 3.2.
|
242
|
+
rubygems_version: 3.2.22
|
228
243
|
signing_key:
|
229
244
|
specification_version: 4
|
230
245
|
summary: Full-featured type system for any ruby project.
|