smart_types 0.1.0.alpha5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -1
- data/CHANGELOG.md +46 -0
- data/Gemfile.lock +80 -52
- data/README.md +437 -27
- data/Rakefile +1 -1
- data/bin/console +2 -2
- data/lib/smart_core/types.rb +2 -0
- data/lib/smart_core/types/errors.rb +16 -0
- data/lib/smart_core/types/primitive.rb +109 -24
- data/lib/smart_core/types/primitive/caster.rb +5 -2
- data/lib/smart_core/types/primitive/checker.rb +5 -2
- data/lib/smart_core/types/primitive/factory.rb +105 -8
- data/lib/smart_core/types/primitive/factory/definition_context.rb +142 -6
- data/lib/smart_core/types/primitive/factory/runtime_type_builder.rb +53 -0
- data/lib/smart_core/types/primitive/invariant_control.rb +67 -0
- data/lib/smart_core/types/primitive/invariant_control/chain.rb +61 -0
- data/lib/smart_core/types/primitive/invariant_control/chain/result.rb +64 -0
- data/lib/smart_core/types/primitive/invariant_control/factory.rb +54 -0
- data/lib/smart_core/types/primitive/invariant_control/factory/chain_definition_context.rb +39 -0
- data/lib/smart_core/types/primitive/invariant_control/result.rb +104 -0
- data/lib/smart_core/types/primitive/invariant_control/single.rb +57 -0
- data/lib/smart_core/types/primitive/invariant_control/single/result.rb +63 -0
- data/lib/smart_core/types/primitive/mult_factory.rb +59 -10
- data/lib/smart_core/types/primitive/mult_factory/definition_context.rb +27 -3
- data/lib/smart_core/types/primitive/mult_validator.rb +42 -0
- data/lib/smart_core/types/primitive/mult_validator/result.rb +8 -0
- data/lib/smart_core/types/primitive/nilable_factory.rb +31 -9
- data/lib/smart_core/types/primitive/nilable_validator.rb +83 -0
- data/lib/smart_core/types/primitive/nilable_validator/result.rb +78 -0
- data/lib/smart_core/types/primitive/runtime_attributes_checker.rb +77 -0
- data/lib/smart_core/types/primitive/sum_factory.rb +59 -10
- data/lib/smart_core/types/primitive/sum_factory/definition_context.rb +26 -2
- data/lib/smart_core/types/primitive/sum_validator.rb +117 -0
- data/lib/smart_core/types/primitive/sum_validator/result.rb +100 -0
- data/lib/smart_core/types/primitive/undefined_caster.rb +7 -5
- data/lib/smart_core/types/primitive/validator.rb +93 -0
- data/lib/smart_core/types/primitive/validator/result.rb +78 -0
- data/lib/smart_core/types/protocol.rb +7 -0
- data/lib/smart_core/types/protocol/instance_of.rb +19 -0
- data/lib/smart_core/types/system.rb +21 -5
- data/lib/smart_core/types/value.rb +16 -0
- data/lib/smart_core/types/value/array.rb +3 -0
- data/lib/smart_core/types/value/big_decimal.rb +31 -0
- data/lib/smart_core/types/value/boolean.rb +3 -0
- data/lib/smart_core/types/value/class.rb +3 -0
- data/lib/smart_core/types/value/comparable.rb +13 -0
- data/lib/smart_core/types/value/date.rb +24 -0
- data/lib/smart_core/types/value/date_time.rb +24 -0
- data/lib/smart_core/types/value/enumerable.rb +13 -0
- data/lib/smart_core/types/value/enumerator.rb +13 -0
- data/lib/smart_core/types/value/enumerator_chain.rb +13 -0
- data/lib/smart_core/types/value/float.rb +9 -2
- data/lib/smart_core/types/value/hash.rb +11 -1
- data/lib/smart_core/types/value/integer.rb +13 -3
- data/lib/smart_core/types/value/io.rb +13 -0
- data/lib/smart_core/types/value/method.rb +9 -0
- data/lib/smart_core/types/value/module.rb +3 -0
- data/lib/smart_core/types/value/nil.rb +3 -3
- data/lib/smart_core/types/value/numeric.rb +16 -3
- data/lib/smart_core/types/value/proc.rb +14 -1
- data/lib/smart_core/types/value/range.rb +9 -0
- data/lib/smart_core/types/value/rational.rb +13 -0
- data/lib/smart_core/types/value/set.rb +21 -0
- data/lib/smart_core/types/value/string.rb +10 -1
- data/lib/smart_core/types/value/string_io.rb +15 -0
- data/lib/smart_core/types/value/symbol.rb +10 -1
- data/lib/smart_core/types/value/text.rb +21 -4
- data/lib/smart_core/types/value/time.rb +24 -0
- data/lib/smart_core/types/value/time_based.rb +32 -0
- data/lib/smart_core/types/value/unbound_method.rb +9 -0
- data/lib/smart_core/types/variadic.rb +7 -0
- data/lib/smart_core/types/variadic/tuple.rb +23 -0
- data/lib/smart_core/types/version.rb +2 -2
- data/smart_types.gemspec +6 -5
- metadata +69 -23
- data/.travis.yml +0 -20
- data/lib/smart_core/types/primitive/mult_checker.rb +0 -31
- data/lib/smart_core/types/primitive/nilable_checker.rb +0 -37
- data/lib/smart_core/types/primitive/sum_checker.rb +0 -31
- data/lib/smart_core/types/system/definition_dsl.rb +0 -40
- data/lib/smart_core/types/system/producer_dsl.rb +0 -30
data/.travis.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
os: linux
|
5
|
-
before_install: gem install bundler -v 2.1.2
|
6
|
-
script:
|
7
|
-
- bundle exec rake rubocop
|
8
|
-
- bundle exec rake rspec
|
9
|
-
jobs:
|
10
|
-
fast_finish: true
|
11
|
-
include:
|
12
|
-
- rvm: 2.4.9
|
13
|
-
- rvm: 2.5.7
|
14
|
-
- rvm: 2.6.5
|
15
|
-
- rvm: 2.7.0
|
16
|
-
- rvm: ruby-head
|
17
|
-
- rvm: jruby-head
|
18
|
-
allow_failures:
|
19
|
-
- rvm: ruby-head
|
20
|
-
- rvm: jruby-head
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.1.0
|
5
|
-
class SmartCore::Types::Primitive::MultChecker
|
6
|
-
# @param [Array<SmartCore::Types::Primitive::Checker>]
|
7
|
-
# @return [void]
|
8
|
-
#
|
9
|
-
# @api private
|
10
|
-
# @since 0.1.0
|
11
|
-
def initialize(*checkers)
|
12
|
-
@checkers = checkers
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param value [Any]
|
16
|
-
# @return [Boolean]
|
17
|
-
#
|
18
|
-
# @api private
|
19
|
-
# @since 0.1.0
|
20
|
-
def call(value)
|
21
|
-
checkers.all? { |checker| checker.call(value) }
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# @return [Array<SmartCore::Types::Primitive::Checker>]
|
27
|
-
#
|
28
|
-
# @api private
|
29
|
-
# @since 0.1.0
|
30
|
-
attr_reader :checkers
|
31
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.1.0
|
5
|
-
class SmartCore::Types::Primitive::NilableChecker
|
6
|
-
# @param checker [Checker, SumChecker, MultChecker, NilableChecker]
|
7
|
-
# @return [void]
|
8
|
-
#
|
9
|
-
# @api private
|
10
|
-
# @since 0.1.0
|
11
|
-
def initialize(checker)
|
12
|
-
@checker = checker
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param value [Any]
|
16
|
-
# @return [Boolean]
|
17
|
-
#
|
18
|
-
# @api private
|
19
|
-
# @since 0.1.0
|
20
|
-
def call(value)
|
21
|
-
# rubocop:disable Style/NilComparison
|
22
|
-
# NOTE: #nil? is not used cuz BasicObject has no #nil? method
|
23
|
-
(value == nil) ? true : checker.call(value)
|
24
|
-
# rubocop:enable Style/NilComparison
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
# @return [SmartCore::Types::Primitive::Checker]
|
30
|
-
# @return [SmartCore::Types::Primitive::MultChecker]
|
31
|
-
# @return [SmartCore::Types::Primitive::SumChecker]
|
32
|
-
# @return [SmartCore::Types::Primitive::NilableChecker]
|
33
|
-
#
|
34
|
-
# @api private
|
35
|
-
# @since 0.1.0
|
36
|
-
attr_reader :checker
|
37
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.1.0
|
5
|
-
class SmartCore::Types::Primitive::SumChecker
|
6
|
-
# @param [Array<SmartCore::Types::Primitive::Checker>]
|
7
|
-
# @return [void]
|
8
|
-
#
|
9
|
-
# @api private
|
10
|
-
# @since 0.1.0
|
11
|
-
def initialize(*checkers)
|
12
|
-
@checkers = checkers
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param value [Any]
|
16
|
-
# @return [Boolean]
|
17
|
-
#
|
18
|
-
# @api private
|
19
|
-
# @since 0.1.0
|
20
|
-
def call(value)
|
21
|
-
checkers.any? { |checker| checker.call(value) }
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# @return [Array<SmartCore::Types::Primitive::Checker>]
|
27
|
-
#
|
28
|
-
# @api private
|
29
|
-
# @since 0.1.0
|
30
|
-
attr_reader :checkers
|
31
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.1.0
|
5
|
-
module SmartCore::Types::System::DefinitionDSL
|
6
|
-
class << self
|
7
|
-
# @param base_klass [Class]
|
8
|
-
# @return [void]
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
# @since 0.1.0
|
12
|
-
def included(base_klass)
|
13
|
-
base_klass.extend(ClassMethods)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# @api private
|
18
|
-
# @since 0.1.0
|
19
|
-
module ClassMethods
|
20
|
-
# @param types [Array<SmartCore::Types::Pirmitive>]
|
21
|
-
# @param type_definition [Block]
|
22
|
-
# @return [SmartCore::Types::Primitive]
|
23
|
-
#
|
24
|
-
# @api public
|
25
|
-
# @since 0.1.0
|
26
|
-
def type_sum(*types, &type_definition)
|
27
|
-
SmartCore::Types::Primitive::SumFactory.create_type(types, type_definition)
|
28
|
-
end
|
29
|
-
|
30
|
-
# @param types [Array<SmartCore::Types::Pirmitive>]
|
31
|
-
# @param type_definition [Block]
|
32
|
-
# @return [SmartCore::Types::Primitive]
|
33
|
-
#
|
34
|
-
# @api public
|
35
|
-
# @since 0.1.0
|
36
|
-
def type_mult(*types, &type_definition)
|
37
|
-
SmartCore::Types::Primitive::MultFactory.create_type(types, type_definition)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.1.0
|
5
|
-
module SmartCore::Types::System::ProducerDSL
|
6
|
-
class << self
|
7
|
-
# @param base_klass [Class<SmartCore::Types::Primitive>]
|
8
|
-
# @return [void]
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
# @since 0.1.0
|
12
|
-
def included(base_klass)
|
13
|
-
base_klass.extend(ClassMethods)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# @api private
|
18
|
-
# @since 0.1.0
|
19
|
-
module ClassMethods
|
20
|
-
# @param type_name [String, Symbol]
|
21
|
-
# @param type_definition [Block]
|
22
|
-
# @return [SmartCore::Types::Primitive]
|
23
|
-
#
|
24
|
-
# @api public
|
25
|
-
# @since 0.1.0
|
26
|
-
def define_type(type_name, &type_definition)
|
27
|
-
self::Factory.create_type(self, type_name, type_definition)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|