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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a77f7989b137f4e3e7c319ad0f825f4484329ec4ff87ad04d31b9decae9bdce7
4
- data.tar.gz: 7e05552fb246042a12a708089065f0916eac5565bcc4de61e4bbea5cb4d76c21
3
+ metadata.gz: 7d46db58ce368955b324f4acb5fbfa74100789abe263c8e83fa8a73c482b6dd4
4
+ data.tar.gz: f5377e4cc8693855b885d197f1d5b8429ba78efc30b781703a2ba95230d58d2b
5
5
  SHA512:
6
- metadata.gz: 800dc2c99f6eeee87f522576483cb7583e8f63a21a98aa5ed6b7106499406336d31b4414a4146a33bd3be251268cf3f916236662398199c2e17ba5c11c4ab0d6
7
- data.tar.gz: b771a4a428498a0bad62fc8f2cf67728117f3d47822da01086e70f386f822c4e001bb73ad609bc9ef049d06743ee3dfe13744db4d13964d4def5b058a323ad66
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_types (0.4.0)
4
+ smart_types (0.6.0)
5
5
  smart_engine (~> 0.11)
6
6
 
7
7
  GEM
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Rustam Ibragimov
3
+ Copyright (c) 2020-2021 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
@@ -1,4 +1,4 @@
1
- # SmartCore::Types · [![Gem Version](https://badge.fury.io/rb/smart_types.svg)](https://badge.fury.io/rb/smart_types)
1
+ # SmartCore::Types · [![Supporting](https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_badge.png)](https://github.com/Cado-Labs/) · [![Gem Version](https://badge.fury.io/rb/smart_types.svg)](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
@@ -2,6 +2,9 @@
2
2
 
3
3
  # @api public
4
4
  # @since 0.3.0
5
+ # @version 0.6.0
5
6
  class SmartCore::Types::Variadic < SmartCore::Types::Primitive
7
+ require_relative 'variadic/array_of'
8
+ require_relative 'variadic/enum'
6
9
  require_relative 'variadic/tuple'
7
10
  end
@@ -6,7 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- # @version 0.4.0
10
- VERSION = '0.4.0'
9
+ # @version 0.6.0
10
+ VERSION = '0.6.0'
11
11
  end
12
12
  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.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-01-17 00:00:00.000000000 Z
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