smart_types 0.1.0.alpha3 → 0.2.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/.travis.yml +6 -5
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +74 -48
- data/README.md +292 -22
- data/Rakefile +1 -1
- data/bin/console +2 -2
- data/lib/smart_core/types/errors.rb +4 -0
- data/lib/smart_core/types/primitive.rb +67 -20
- data/lib/smart_core/types/primitive/factory.rb +48 -8
- data/lib/smart_core/types/primitive/factory/definition_context.rb +116 -6
- data/lib/smart_core/types/primitive/invariant_control.rb +64 -0
- data/lib/smart_core/types/primitive/invariant_control/chain.rb +58 -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 +54 -0
- data/lib/smart_core/types/primitive/invariant_control/single/result.rb +63 -0
- data/lib/smart_core/types/primitive/mult_factory.rb +25 -10
- data/lib/smart_core/types/primitive/mult_factory/definition_context.rb +5 -3
- data/lib/smart_core/types/primitive/mult_validator.rb +34 -0
- data/lib/smart_core/types/primitive/mult_validator/result.rb +8 -0
- data/lib/smart_core/types/primitive/nilable_factory.rb +24 -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/sum_factory.rb +25 -10
- data/lib/smart_core/types/primitive/sum_factory/definition_context.rb +4 -2
- data/lib/smart_core/types/primitive/sum_validator.rb +101 -0
- data/lib/smart_core/types/primitive/sum_validator/result.rb +100 -0
- data/lib/smart_core/types/primitive/undefined_caster.rb +3 -4
- data/lib/smart_core/types/primitive/validator.rb +84 -0
- data/lib/smart_core/types/primitive/validator/result.rb +78 -0
- data/lib/smart_core/types/system.rb +21 -5
- data/lib/smart_core/types/value.rb +17 -0
- data/lib/smart_core/types/value/big_decimal.rb +28 -0
- data/lib/smart_core/types/value/comparable.rb +13 -0
- data/lib/smart_core/types/value/date.rb +21 -0
- data/lib/smart_core/types/value/date_time.rb +21 -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 +6 -2
- data/lib/smart_core/types/value/hash.rb +8 -1
- data/lib/smart_core/types/value/integer.rb +10 -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/nil.rb +9 -0
- data/lib/smart_core/types/value/numeric.rb +13 -3
- data/lib/smart_core/types/value/proc.rb +11 -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 +13 -0
- data/lib/smart_core/types/value/string.rb +7 -1
- data/lib/smart_core/types/value/string_io.rb +13 -0
- data/lib/smart_core/types/value/symbol.rb +7 -1
- data/lib/smart_core/types/value/text.rb +16 -1
- data/lib/smart_core/types/value/time.rb +21 -0
- data/lib/smart_core/types/value/time_based.rb +29 -0
- data/lib/smart_core/types/value/unbound_method.rb +9 -0
- data/lib/smart_core/types/version.rb +2 -2
- data/smart_types.gemspec +6 -5
- metadata +64 -22
- 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
@@ -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
|