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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -1
  3. data/CHANGELOG.md +46 -0
  4. data/Gemfile.lock +80 -52
  5. data/README.md +437 -27
  6. data/Rakefile +1 -1
  7. data/bin/console +2 -2
  8. data/lib/smart_core/types.rb +2 -0
  9. data/lib/smart_core/types/errors.rb +16 -0
  10. data/lib/smart_core/types/primitive.rb +109 -24
  11. data/lib/smart_core/types/primitive/caster.rb +5 -2
  12. data/lib/smart_core/types/primitive/checker.rb +5 -2
  13. data/lib/smart_core/types/primitive/factory.rb +105 -8
  14. data/lib/smart_core/types/primitive/factory/definition_context.rb +142 -6
  15. data/lib/smart_core/types/primitive/factory/runtime_type_builder.rb +53 -0
  16. data/lib/smart_core/types/primitive/invariant_control.rb +67 -0
  17. data/lib/smart_core/types/primitive/invariant_control/chain.rb +61 -0
  18. data/lib/smart_core/types/primitive/invariant_control/chain/result.rb +64 -0
  19. data/lib/smart_core/types/primitive/invariant_control/factory.rb +54 -0
  20. data/lib/smart_core/types/primitive/invariant_control/factory/chain_definition_context.rb +39 -0
  21. data/lib/smart_core/types/primitive/invariant_control/result.rb +104 -0
  22. data/lib/smart_core/types/primitive/invariant_control/single.rb +57 -0
  23. data/lib/smart_core/types/primitive/invariant_control/single/result.rb +63 -0
  24. data/lib/smart_core/types/primitive/mult_factory.rb +59 -10
  25. data/lib/smart_core/types/primitive/mult_factory/definition_context.rb +27 -3
  26. data/lib/smart_core/types/primitive/mult_validator.rb +42 -0
  27. data/lib/smart_core/types/primitive/mult_validator/result.rb +8 -0
  28. data/lib/smart_core/types/primitive/nilable_factory.rb +31 -9
  29. data/lib/smart_core/types/primitive/nilable_validator.rb +83 -0
  30. data/lib/smart_core/types/primitive/nilable_validator/result.rb +78 -0
  31. data/lib/smart_core/types/primitive/runtime_attributes_checker.rb +77 -0
  32. data/lib/smart_core/types/primitive/sum_factory.rb +59 -10
  33. data/lib/smart_core/types/primitive/sum_factory/definition_context.rb +26 -2
  34. data/lib/smart_core/types/primitive/sum_validator.rb +117 -0
  35. data/lib/smart_core/types/primitive/sum_validator/result.rb +100 -0
  36. data/lib/smart_core/types/primitive/undefined_caster.rb +7 -5
  37. data/lib/smart_core/types/primitive/validator.rb +93 -0
  38. data/lib/smart_core/types/primitive/validator/result.rb +78 -0
  39. data/lib/smart_core/types/protocol.rb +7 -0
  40. data/lib/smart_core/types/protocol/instance_of.rb +19 -0
  41. data/lib/smart_core/types/system.rb +21 -5
  42. data/lib/smart_core/types/value.rb +16 -0
  43. data/lib/smart_core/types/value/array.rb +3 -0
  44. data/lib/smart_core/types/value/big_decimal.rb +31 -0
  45. data/lib/smart_core/types/value/boolean.rb +3 -0
  46. data/lib/smart_core/types/value/class.rb +3 -0
  47. data/lib/smart_core/types/value/comparable.rb +13 -0
  48. data/lib/smart_core/types/value/date.rb +24 -0
  49. data/lib/smart_core/types/value/date_time.rb +24 -0
  50. data/lib/smart_core/types/value/enumerable.rb +13 -0
  51. data/lib/smart_core/types/value/enumerator.rb +13 -0
  52. data/lib/smart_core/types/value/enumerator_chain.rb +13 -0
  53. data/lib/smart_core/types/value/float.rb +9 -2
  54. data/lib/smart_core/types/value/hash.rb +11 -1
  55. data/lib/smart_core/types/value/integer.rb +13 -3
  56. data/lib/smart_core/types/value/io.rb +13 -0
  57. data/lib/smart_core/types/value/method.rb +9 -0
  58. data/lib/smart_core/types/value/module.rb +3 -0
  59. data/lib/smart_core/types/value/nil.rb +3 -3
  60. data/lib/smart_core/types/value/numeric.rb +16 -3
  61. data/lib/smart_core/types/value/proc.rb +14 -1
  62. data/lib/smart_core/types/value/range.rb +9 -0
  63. data/lib/smart_core/types/value/rational.rb +13 -0
  64. data/lib/smart_core/types/value/set.rb +21 -0
  65. data/lib/smart_core/types/value/string.rb +10 -1
  66. data/lib/smart_core/types/value/string_io.rb +15 -0
  67. data/lib/smart_core/types/value/symbol.rb +10 -1
  68. data/lib/smart_core/types/value/text.rb +21 -4
  69. data/lib/smart_core/types/value/time.rb +24 -0
  70. data/lib/smart_core/types/value/time_based.rb +32 -0
  71. data/lib/smart_core/types/value/unbound_method.rb +9 -0
  72. data/lib/smart_core/types/variadic.rb +7 -0
  73. data/lib/smart_core/types/variadic/tuple.rb +23 -0
  74. data/lib/smart_core/types/version.rb +2 -2
  75. data/smart_types.gemspec +6 -5
  76. metadata +69 -23
  77. data/.travis.yml +0 -20
  78. data/lib/smart_core/types/primitive/mult_checker.rb +0 -31
  79. data/lib/smart_core/types/primitive/nilable_checker.rb +0 -37
  80. data/lib/smart_core/types/primitive/sum_checker.rb +0 -31
  81. data/lib/smart_core/types/system/definition_dsl.rb +0 -40
  82. data/lib/smart_core/types/system/producer_dsl.rb +0 -30
@@ -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