core-type 0.0.0 → 0.1.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/lib/core/type/coercions/array.rb +1 -3
  4. data/lib/core/type/coercions/decimal.rb +1 -3
  5. data/lib/core/type/coercions/float.rb +1 -3
  6. data/lib/core/type/coercions/hash.rb +1 -3
  7. data/lib/core/type/coercions/integer.rb +1 -3
  8. data/lib/core/type/coercions/string.rb +1 -3
  9. data/lib/core/type/coercions/symbol.rb +1 -3
  10. data/lib/core/type/conversions/array.rb +1 -3
  11. data/lib/core/type/conversions/decimal.rb +1 -3
  12. data/lib/core/type/conversions/float.rb +1 -3
  13. data/lib/core/type/conversions/hash.rb +1 -3
  14. data/lib/core/type/conversions/integer.rb +1 -3
  15. data/lib/core/type/conversions/string.rb +1 -3
  16. data/lib/core/type/conversions/symbol.rb +1 -3
  17. data/lib/core/type/inputs/array.rb +1 -2
  18. data/lib/core/type/inputs/boolean.rb +1 -3
  19. data/lib/core/type/inputs/date.rb +1 -3
  20. data/lib/core/type/inputs/date_time.rb +1 -3
  21. data/lib/core/type/inputs/hash.rb +1 -2
  22. data/lib/core/type/inputs/time.rb +1 -3
  23. data/lib/core/type/types/array.rb +1 -3
  24. data/lib/core/type/types/boolean.rb +1 -3
  25. data/lib/core/type/types/class.rb +1 -3
  26. data/lib/core/type/types/date.rb +1 -3
  27. data/lib/core/type/types/date_time.rb +1 -3
  28. data/lib/core/type/types/decimal.rb +1 -3
  29. data/lib/core/type/types/false.rb +1 -3
  30. data/lib/core/type/types/float.rb +1 -3
  31. data/lib/core/type/types/hash.rb +1 -3
  32. data/lib/core/type/types/integer.rb +1 -3
  33. data/lib/core/type/types/nil.rb +1 -3
  34. data/lib/core/type/types/object.rb +1 -3
  35. data/lib/core/type/types/string.rb +1 -3
  36. data/lib/core/type/types/symbol.rb +1 -3
  37. data/lib/core/type/types/time.rb +1 -3
  38. data/lib/core/type/types/true.rb +1 -3
  39. data/lib/core/type/validator.rb +2 -2
  40. data/lib/core/type/version.rb +1 -1
  41. data/lib/core/type.rb +108 -4
  42. metadata +11 -12
  43. data/lib/is/typed.rb +0 -112
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 155ab0fe505d9c79983751a3be7825bac7a5c75babba16c83cdc9270b4273497
4
- data.tar.gz: b8b265bd9d14335c12bb8a9b61450f37f117d9a2103e22c9bb3544ae1a924143
3
+ metadata.gz: e2d4b0a2f6620472c792c83050b13047d7f0465d2047bde18e0b0fb993d94e87
4
+ data.tar.gz: b030e6e63037cc970d000dc4a6541d33d1911b2b81241efd6d1f84a8bb3a940b
5
5
  SHA512:
6
- metadata.gz: 42dc10420b09d0d0380e73b995c19f2c4137d985fb840942a2c630dbd5a8f1dc058ac8665734e9c501cd9a98dc4a160bf30be757cf71fc45a77bb9b32ff2bf9e
7
- data.tar.gz: a5e416dde51ed16efb6ffff62b70d3a1b0d657b500d3179b2a16ee169a2edb3ffd1abf6ed0bd595693ab66d18dd002b911615e3d13f21a34f790ef26ba7205ce
6
+ metadata.gz: '09766d4ae818d2ae4b3dd8e3a24f2568d63e9d0f810b5ae9682ef34960c0304d1b34dd14fc74949b6e1dceaf4f326ab0f41a73ce9535fd461a3deed787ebd942'
7
+ data.tar.gz: 7aa279892755c016f2f5c610f7ca1867bb9ede1b4c7445ed7878886ccab3806afbc47ec8b50925c9afe0a22df9664e336e19cdd577f3f0e4180da2092b5bac68
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [v0.1.0](https://github.com/bryanp/corerb/releases/tag/2023-12-24)
2
+
3
+ *released on 2023-12-24*
4
+
5
+ * `dep` [#143](https://github.com/bryanp/corerb/pull/143) Deprecate `Is::*` and `Refine::*` namespaces ([bryanp](https://github.com/bryanp))
6
+
1
7
  ## [v0.0.0](https://github.com/bryanp/corerb/releases/tag/2023-12-19)
2
8
 
3
9
  *released on 2023-12-19*
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Coercions
8
6
  # [public] Coercible array type.
9
7
  #
10
8
  class Array
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  value.to_ary
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  require "bigdecimal"
6
4
  require "bigdecimal/util"
7
5
 
@@ -11,7 +9,7 @@ module Core
11
9
  # [public] Coercible decimal type.
12
10
  #
13
11
  class Decimal
14
- include Is::Typed
12
+ include Core::Type
15
13
 
16
14
  def self.build(value)
17
15
  value.to_d
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Coercions
8
6
  # [public] Coercible float type.
9
7
  #
10
8
  class Float
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  Kernel.Float(value)
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Coercions
8
6
  # [public] Coercible hash type.
9
7
  #
10
8
  class Hash
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  value.to_hash
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Coercions
8
6
  # [public] Coercible integer type.
9
7
  #
10
8
  class Integer
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  value.to_int
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Coercions
8
6
  # [public] Coercible string type.
9
7
  #
10
8
  class String
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  value.to_str
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Coercions
8
6
  # [public] Coercible symbol type.
9
7
  #
10
8
  class Symbol
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  value.to_sym
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Conversions
8
6
  # [public] Convertible array type.
9
7
  #
10
8
  class Array
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  Kernel.Array(value)
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  require "bigdecimal"
6
4
  require "bigdecimal/util"
7
5
 
@@ -11,7 +9,7 @@ module Core
11
9
  # [public] Convertible decimal type.
12
10
  #
13
11
  class Decimal
14
- include Is::Typed
12
+ include Core::Type
15
13
 
16
14
  def self.build(value)
17
15
  value.to_d
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Conversions
8
6
  # [public] Convertible float type.
9
7
  #
10
8
  class Float
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  case value
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Conversions
8
6
  # [public] Convertible hash type.
9
7
  #
10
8
  class Hash
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  if value.respond_to?(:to_hash)
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Conversions
8
6
  # [public] Convertible integer type.
9
7
  #
10
8
  class Integer
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  case value
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Conversions
8
6
  # [public] Convertible string type.
9
7
  #
10
8
  class String
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  Kernel.String(value)
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Conversions
8
6
  # [public] Convertible symbol type.
9
7
  #
10
8
  class Symbol
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  def self.build(value)
14
12
  Kernel.String(value).to_sym
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
3
  require_relative "../conversions/array"
5
4
 
6
5
  module Core
@@ -9,7 +8,7 @@ module Core
9
8
  # [public]
10
9
  #
11
10
  class Array
12
- include Is::Typed
11
+ include Core::Type
13
12
 
14
13
  def self.build(value)
15
14
  return [] if value == ""
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Inputs
8
6
  # [public]
9
7
  #
10
8
  class Boolean
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  FALSE_VALUES = [
14
12
  0,
@@ -2,15 +2,13 @@
2
2
 
3
3
  require "date"
4
4
 
5
- require_relative "../../../is/typed"
6
-
7
5
  module Core
8
6
  module Type
9
7
  module Inputs
10
8
  # [public]
11
9
  #
12
10
  class Date
13
- include Is::Typed
11
+ include Core::Type
14
12
 
15
13
  def self.build(value)
16
14
  ::Date.parse(value)
@@ -2,15 +2,13 @@
2
2
 
3
3
  require "date"
4
4
 
5
- require_relative "../../../is/typed"
6
-
7
5
  module Core
8
6
  module Type
9
7
  module Inputs
10
8
  # [public]
11
9
  #
12
10
  class DateTime
13
- include Is::Typed
11
+ include Core::Type
14
12
 
15
13
  def self.build(value)
16
14
  ::DateTime.parse(value)
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
3
  require_relative "../conversions/hash"
5
4
 
6
5
  module Core
@@ -9,7 +8,7 @@ module Core
9
8
  # [public]
10
9
  #
11
10
  class Hash
12
- include Is::Typed
11
+ include Core::Type
13
12
 
14
13
  def self.build(value)
15
14
  return {} if value == ""
@@ -2,15 +2,13 @@
2
2
 
3
3
  require "date"
4
4
 
5
- require_relative "../../../is/typed"
6
-
7
5
  module Core
8
6
  module Type
9
7
  module Inputs
10
8
  # [public]
11
9
  #
12
10
  class Time
13
- include Is::Typed
11
+ include Core::Type
14
12
 
15
13
  def self.build(value)
16
14
  ::DateTime.parse(value).to_time
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict array type.
9
7
  #
10
8
  class Array
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict boolean type.
9
7
  #
10
8
  class Boolean
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict class type.
9
7
  #
10
8
  class Class
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict date type.
9
7
  #
10
8
  class Date
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  require "date"
6
4
 
7
5
  module Core
@@ -10,7 +8,7 @@ module Core
10
8
  # [public] Strict datetime type.
11
9
  #
12
10
  class DateTime
13
- include Is::Typed
11
+ include Core::Type
14
12
 
15
13
  # [public]
16
14
  #
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  require "bigdecimal"
6
4
 
7
5
  module Core
@@ -10,7 +8,7 @@ module Core
10
8
  # [public] Strict decimal type.
11
9
  #
12
10
  class Decimal
13
- include Is::Typed
11
+ include Core::Type
14
12
 
15
13
  # [public]
16
14
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict false type.
9
7
  #
10
8
  class False
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict float type.
9
7
  #
10
8
  class Float
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict hash type.
9
7
  #
10
8
  class Hash
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict integer type.
9
7
  #
10
8
  class Integer
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict nil type.
9
7
  #
10
8
  class Nil
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict object type.
9
7
  #
10
8
  class Object
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict string type.
9
7
  #
10
8
  class String
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict symbol type.
9
7
  #
10
8
  class Symbol
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict time type.
9
7
  #
10
8
  class Time
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../../is/typed"
4
-
5
3
  module Core
6
4
  module Type
7
5
  module Types
8
6
  # [public] Strict true type.
9
7
  #
10
8
  class True
11
- include Is::Typed
9
+ include Core::Type
12
10
 
13
11
  # [public]
14
12
  #
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "is/pipeline"
3
+ require "core/pipeline"
4
4
 
5
5
  require_relative "check_failed"
6
6
 
@@ -9,7 +9,7 @@ module Core
9
9
  # [public]
10
10
  #
11
11
  class Validator
12
- include Is::Pipeline
12
+ include Core::Pipeline
13
13
 
14
14
  def initialize(type)
15
15
  @type = type
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Type
5
- VERSION = "0.0.0"
5
+ VERSION = "0.1.0"
6
6
 
7
7
  # [public]
8
8
  #
data/lib/core/type.rb CHANGED
@@ -1,19 +1,123 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "core/extension"
4
+ require "core/global"
5
+ require "core/state"
6
+
3
7
  module Core
8
+ # [public]
9
+ #
4
10
  module Type
5
11
  require_relative "type/check_failed"
6
- require_relative "type/coercions"
7
12
  require_relative "type/composed"
13
+ require_relative "type/validator"
14
+ require_relative "type/version"
15
+
16
+ extend Core::Extension
17
+
18
+ extends :definition do
19
+ # [public]
20
+ #
21
+ def check(description = nil, &block)
22
+ validator.check(description, &block)
23
+ end
24
+
25
+ # [public]
26
+ #
27
+ def normalize(value)
28
+ value
29
+ end
30
+ end
31
+
32
+ extends :definition, prepend: true do
33
+ # [public]
34
+ #
35
+ def build(value = nil)
36
+ global.build(value)
37
+ end
38
+
39
+ # [public]
40
+ #
41
+ def |(other)
42
+ Core::Type::Composed.new(self) | other
43
+ end
44
+ end
45
+
46
+ extends :implementation do
47
+ # [public]
48
+ #
49
+ attr_reader :builder
50
+
51
+ # [public]
52
+ #
53
+ def build(value = nil)
54
+ finalize.build(value)
55
+ end
56
+
57
+ # [public]
58
+ #
59
+ def try(value = nil)
60
+ finalize.try(value)
61
+ end
62
+
63
+ # [public]
64
+ #
65
+ def valid?(value = nil)
66
+ finalize.valid?(value)
67
+ end
68
+
69
+ # [public]
70
+ #
71
+ def finalize
72
+ super if defined?(super)
73
+
74
+ @builder = self.class.method(:build).super_method
75
+ @normalizer = self.class.method(:normalize)
76
+
77
+ singleton_class.class_eval(<<~CODE, __FILE__, __LINE__ + 1)
78
+ def build(value = nil)
79
+ value = @normalizer.call(value)
80
+ @validator.call(value)
81
+ @builder.call(value)
82
+ rescue ArgumentError, TypeError => error
83
+ raise Core::Type::Error, error.message
84
+ end
85
+
86
+ def try(value = nil)
87
+ value = @normalizer.call(value)
88
+ if @validator.call(value, true)
89
+ @builder.call(value)
90
+ end
91
+ end
92
+
93
+ def valid?(value = nil)
94
+ value = @normalizer.call(value)
95
+ @validator.call(value, true)
96
+ end
97
+ CODE
98
+
99
+ self
100
+ end
101
+ end
102
+
103
+ extends dependencies: [
104
+ Core::Global,
105
+ Core::State
106
+ ]
107
+
108
+ applies do
109
+ # [public]
110
+ #
111
+ state :validator, default: Core::Type::Validator.new(self)
112
+ end
113
+
114
+ require_relative "type/coercions"
8
115
  require_relative "type/conversions"
9
116
  require_relative "type/inputs"
10
117
  require_relative "type/types"
11
- require_relative "type/version"
12
118
 
13
119
  # Allow default strict types to be accessed through the top-level `Core::Type` namespace.
14
120
  #
15
121
  include Types
16
122
  end
17
123
  end
18
-
19
- require_relative "../is/typed"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core-type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-20 00:00:00.000000000 Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.4'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: core-global
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: '0.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: core-pipeline
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.5'
47
+ version: '0.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.5'
54
+ version: '0.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: core-state
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.1'
61
+ version: '0.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.1'
68
+ version: '0.2'
69
69
  description: Types for Ruby programs.
70
70
  email: bryan@bryanp.org
71
71
  executables: []
@@ -126,7 +126,6 @@ files:
126
126
  - lib/core/type/types/true.rb
127
127
  - lib/core/type/validator.rb
128
128
  - lib/core/type/version.rb
129
- - lib/is/typed.rb
130
129
  homepage: https://github.com/bryanp/corerb/
131
130
  licenses:
132
131
  - MPL-2.0
@@ -146,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
145
  - !ruby/object:Gem::Version
147
146
  version: '0'
148
147
  requirements: []
149
- rubygems_version: 3.4.22
148
+ rubygems_version: 3.5.1
150
149
  signing_key:
151
150
  specification_version: 4
152
151
  summary: Types for Ruby programs.
data/lib/is/typed.rb DELETED
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "is/extension"
4
- require "is/global"
5
- require "is/stateful"
6
-
7
- require_relative "../core/type/composed"
8
- require_relative "../core/type/validator"
9
-
10
- module Is
11
- # [public]
12
- #
13
- module Typed
14
- extend Is::Extension
15
-
16
- extends :definition do
17
- # [public]
18
- #
19
- def check(description = nil, &block)
20
- validator.check(description, &block)
21
- end
22
-
23
- # [public]
24
- #
25
- def normalize(value)
26
- value
27
- end
28
- end
29
-
30
- extends :definition, prepend: true do
31
- # [public]
32
- #
33
- def build(value = nil)
34
- global.build(value)
35
- end
36
-
37
- # [public]
38
- #
39
- def |(other)
40
- Core::Type::Composed.new(self) | other
41
- end
42
- end
43
-
44
- extends :implementation do
45
- # [public]
46
- #
47
- attr_reader :builder
48
-
49
- # [public]
50
- #
51
- def build(value = nil)
52
- finalize.build(value)
53
- end
54
-
55
- # [public]
56
- #
57
- def try(value = nil)
58
- finalize.try(value)
59
- end
60
-
61
- # [public]
62
- #
63
- def valid?(value = nil)
64
- finalize.valid?(value)
65
- end
66
-
67
- # [public]
68
- #
69
- def finalize
70
- super if defined?(super)
71
-
72
- @builder = self.class.method(:build).super_method
73
- @normalizer = self.class.method(:normalize)
74
-
75
- singleton_class.class_eval(<<~CODE, __FILE__, __LINE__ + 1)
76
- def build(value = nil)
77
- value = @normalizer.call(value)
78
- @validator.call(value)
79
- @builder.call(value)
80
- rescue ArgumentError, TypeError => error
81
- raise Core::Type::Error, error.message
82
- end
83
-
84
- def try(value = nil)
85
- value = @normalizer.call(value)
86
- if @validator.call(value, true)
87
- @builder.call(value)
88
- end
89
- end
90
-
91
- def valid?(value = nil)
92
- value = @normalizer.call(value)
93
- @validator.call(value, true)
94
- end
95
- CODE
96
-
97
- self
98
- end
99
- end
100
-
101
- extends dependencies: [
102
- Is::Global,
103
- Is::Stateful
104
- ]
105
-
106
- applies do
107
- # [public]
108
- #
109
- state :validator, default: Core::Type::Validator.new(self)
110
- end
111
- end
112
- end