smart_types 0.4.0 → 0.6.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +25 -2
- data/lib/smart_core/types/variadic/array_of.rb +23 -0
- data/lib/smart_core/types/variadic/enum.rb +11 -0
- data/lib/smart_core/types/variadic.rb +3 -0
- data/lib/smart_core/types/version.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d46db58ce368955b324f4acb5fbfa74100789abe263c8e83fa8a73c482b6dd4
|
4
|
+
data.tar.gz: f5377e4cc8693855b885d197f1d5b8429ba78efc30b781703a2ba95230d58d2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 294f3ef4a287aef01cbf48c6250ece9190effee142b42596a453657f7ed541080d964c4d22e56113c8a7fc80298f2dfd5fefe92159a8499829b34d5a993b0ddb
|
7
|
+
data.tar.gz: a515dad1255bf4b3e757d12011f8c4eedde8a79fd265e5acba10e5a19282c40f3f61d85aa094cb962c1029329b06cd225a828aa9bd23bfaec6e575b89bd945a0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
# [0.6.0] - 2021-04-29
|
5
|
+
### Added
|
6
|
+
- New type of `SmartCode::Types::Variadic` category:
|
7
|
+
- `SmartCore::Types::Variadic::ArrayOf` (`Array` with element types validation)
|
8
|
+
|
9
|
+
|
10
|
+
# [0.5.0] - 2021-01-28
|
11
|
+
### Added
|
12
|
+
- New types of `SmartCore::Types::Variadic` category:
|
13
|
+
- `SmartCore::Types::Variadic::Enum` (a simple enumeration on plain values);
|
14
|
+
|
4
15
|
# [0.4.0] - 2021-01-18
|
5
16
|
### Added
|
6
17
|
- Support for *Ruby 3*;
|
data/Gemfile.lock
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SmartCore::Types · [](https://badge.fury.io/rb/smart_types)
|
1
|
+
# SmartCore::Types · [](https://github.com/Cado-Labs/) · [](https://badge.fury.io/rb/smart_types)
|
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
|
|
@@ -6,6 +6,16 @@ Minimalistic type system for any ruby project. Supports custom type definitionin
|
|
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
|
|
9
|
+
---
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<a href="https://github.com/Cado-Labs">
|
13
|
+
<img src="https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_supporting.svg" alt="Supported by Cado Labs" />
|
14
|
+
</a>
|
15
|
+
</p>
|
16
|
+
|
17
|
+
---
|
18
|
+
|
9
19
|
## Installation
|
10
20
|
|
11
21
|
```ruby
|
@@ -120,10 +130,18 @@ SmartCore::Types::Protocol::InstanceOf(::Time, ::DateTime, ::Date) # time or dat
|
|
120
130
|
#### Variadic:
|
121
131
|
|
122
132
|
```ruby
|
133
|
+
SmartCore::Types::Variadic::ArrayOf
|
134
|
+
SmartCore::Types::Variadic::Enum
|
123
135
|
SmartCore::Types::Variadic::Tuple
|
124
136
|
```
|
125
137
|
|
126
138
|
```ruby
|
139
|
+
# example (SmartCore::Types::Variadic::ArrayOf):
|
140
|
+
SmartCore::Types::Variadic::ArrayOf(::String, ::Array) # array of strings or arrays
|
141
|
+
|
142
|
+
# example (SmartCore::Types::Variadic::Enum):
|
143
|
+
SmartCore::Types::Variadic::Enum('string', 1337, :symbol) # one of enumerated values
|
144
|
+
|
127
145
|
# examples (SmartCore::Types::Variadic::Tuple):
|
128
146
|
SmartCore::Types::Variadic::Tuple(::String, ::Integer, ::Time) # array with signature [<string>, <integer>, <time>]
|
129
147
|
SmartCore::Types::Variadic::Tuple(::Symbol, ::Float) # array with signature [<symbol>, <float>]
|
@@ -481,7 +499,6 @@ SmartCore::Types::Struct::JSONSchema
|
|
481
499
|
SmartCore::Types::Struct::StrictArray
|
482
500
|
SmartCore::Types::Struct::StrictHash
|
483
501
|
SmartCore::Types::Struct::Map
|
484
|
-
SmartCore::Types::Variadic::Enum
|
485
502
|
SmartCore::Types::Protocol::Interface
|
486
503
|
SmartCore::Types::Protocol::Ancestors
|
487
504
|
SmartCore::Types::Protocol::Enumerable
|
@@ -554,6 +571,12 @@ bundle exec rubocop -A
|
|
554
571
|
|
555
572
|
Released under MIT License.
|
556
573
|
|
574
|
+
## Supporting
|
575
|
+
|
576
|
+
<a href="https://github.com/Cado-Labs">
|
577
|
+
<img src="https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_logo.png" alt="Supported by Cado Labs" />
|
578
|
+
</a>
|
579
|
+
|
557
580
|
## Authors
|
558
581
|
|
559
582
|
[Rustam Ibragimov](https://github.com/0exp)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
using SmartCore::Ext::BasicObjectAsObject
|
4
|
+
|
5
|
+
# @api public
|
6
|
+
# @since 0.6.0
|
7
|
+
SmartCore::Types::Variadic.define_type(:ArrayOf) do |type|
|
8
|
+
type.define_caster { |value| SmartCore::Types::Value::Array.cast(value) }
|
9
|
+
|
10
|
+
type.runtime_attributes_checker do |runtime_attrs|
|
11
|
+
runtime_attrs.any? && runtime_attrs.all? do |runtime_attr|
|
12
|
+
runtime_attr.is_a?(::Class)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
type.define_checker do |value, expected_types|
|
17
|
+
next false unless SmartCore::Types::Value::Array.valid?(value)
|
18
|
+
|
19
|
+
value.all? do |elem|
|
20
|
+
expected_types.any? { |expected_type| elem.is_a?(expected_type) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
using SmartCore::Ext::BasicObjectAsObject
|
4
|
+
|
5
|
+
# @api public
|
6
|
+
# @since 0.5.0
|
7
|
+
SmartCore::Types::Variadic.define_type(:Enum) do |type|
|
8
|
+
type.runtime_attributes_checker(&:any?)
|
9
|
+
|
10
|
+
type.define_checker { |value, enum| enum.include?(value) }
|
11
|
+
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.6.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-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_engine
|
@@ -197,6 +197,8 @@ files:
|
|
197
197
|
- lib/smart_core/types/value/time_based.rb
|
198
198
|
- lib/smart_core/types/value/unbound_method.rb
|
199
199
|
- lib/smart_core/types/variadic.rb
|
200
|
+
- lib/smart_core/types/variadic/array_of.rb
|
201
|
+
- lib/smart_core/types/variadic/enum.rb
|
200
202
|
- lib/smart_core/types/variadic/tuple.rb
|
201
203
|
- lib/smart_core/types/version.rb
|
202
204
|
- smart_types.gemspec
|