types 0.4.2 → 0.4.4

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: 1c110776ae58979679f2428639b072820f5dd04e8847475efadfb47a9dd656c0
4
- data.tar.gz: 780e00a548c57bf6eb5e357b5b995e161e377a4620c4a6fe6088919c7399ff62
3
+ metadata.gz: 3785361ab678825d8075ef606e44f2e7515df0037e2c18e13f930709e64a3393
4
+ data.tar.gz: c2ac107637b28611d61a29fca64b7a17b7828b4095501cb9bbd2b638aa57e0ca
5
5
  SHA512:
6
- metadata.gz: 4bdc79038cdf89bb1fedbd371a3a7d3036591badebcf7614d7f5c08d780f40bd6cf4314a30b0981f51f3d5782ae7a205924096f9d16bbfed23a8467ab24c686a
7
- data.tar.gz: dda80bab8fea54302452b0261777c800b3e50f4442678f10edbb35a4b21a855542f44cadce1f69e2b447d2a579e31bf7135c0f66f3ead059965952f5017f34ed
6
+ metadata.gz: 641614eeb0a0a270a7f29523f7ca733c2fd7bf6a2df2bae494b61d6e9449785b51d29a6fac0c40496682c19abc33865e94c775b9e08707303f5641c7280ef43d
7
+ data.tar.gz: faf5130f17a8ec44295157497d20e24df6aa6db5cf7ca193550d53ff0314074e706d2908a79f377e3895ec740a9772abfd7191a151776d4b2278808519c30bc0
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2022-2025, by Samuel Williams.
5
+
6
+ require_relative "generic"
7
+
8
+ module Types
9
+ # Represents an enumerator type with a specific item type.
10
+ #
11
+ # ```ruby
12
+ # type = Types::Enumerator(Types::Integer)
13
+ # type.parse([1, 2, 3].each) # => Enumerator for [1, 2, 3]
14
+ # ```
15
+ class Enumerator
16
+ include Generic
17
+
18
+ # @parameter item_type [Type] The type of the enumerator elements.
19
+ def initialize(item_type)
20
+ @item_type = item_type
21
+ end
22
+
23
+ # @returns [Boolean] true if this is a composite type.
24
+ def composite?
25
+ true
26
+ end
27
+
28
+ # Maps the given enumerator using the item type's parse method.
29
+ # @parameter enumerator [Enumerator] The enumerator to map.
30
+ # @returns [Enumerator] The mapped enumerator.
31
+ def map(enumerator)
32
+ enumerator.map{|value| @item_type.parse(value)}
33
+ end
34
+
35
+ # Parses the input as an enumerator with the specified item type.
36
+ # @parameter input [Object] The value to parse.
37
+ # @returns [Enumerator] The parsed enumerator.
38
+ # @raises [ArgumentError] if the input cannot be converted to an enumerator.
39
+ def parse(input)
40
+ case input
41
+ when ::Enumerator
42
+ return input
43
+ when ::Array
44
+ return input.each
45
+ else
46
+ raise ArgumentError, "Cannot coerce #{input.inspect} into Enumerator!"
47
+ end
48
+ end
49
+
50
+ # @returns [String] the string representation of the enumerator type.
51
+ def to_s
52
+ "Enumerator(#{@item_type})"
53
+ end
54
+
55
+ # @returns [String] the RBS type string, e.g. `Enumerator[String]`.
56
+ def to_rbs
57
+ "Enumerator[#{@item_type.to_rbs}]"
58
+ end
59
+
60
+ # Resolves to the actual Ruby Enumerator class.
61
+ # @returns [Class] The Enumerator class.
62
+ def resolve
63
+ ::Enumerator
64
+ end
65
+ end
66
+
67
+ # Constructs an {Enumerator} type from the given item type.
68
+ # @parameter item_type [Type] The type of the enumerator elements.
69
+ # @returns [Enumerator] a new {Enumerator} type.
70
+ def self.Enumerator(item_type = Any)
71
+ Enumerator.new(item_type)
72
+ end
73
+ end
@@ -18,7 +18,7 @@ module Types
18
18
  # type.valid?(obj) # => true if obj responds to :foo and :bar
19
19
  # ```
20
20
  class Interface
21
- extend Generic
21
+ include Generic
22
22
 
23
23
  # @parameter methods [Array(Symbol)] The required method names.
24
24
  def initialize(methods)
data/lib/types/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2022-2025, by Samuel Williams.
5
5
 
6
6
  module Types
7
- VERSION = "0.4.2"
7
+ VERSION = "0.4.4"
8
8
  end
data/lib/types.rb CHANGED
@@ -11,6 +11,7 @@ require_relative "types/block"
11
11
  require_relative "types/boolean"
12
12
  require_relative "types/class"
13
13
  require_relative "types/decimal"
14
+ require_relative "types/enumerator"
14
15
  require_relative "types/float"
15
16
  require_relative "types/hash"
16
17
  require_relative "types/integer"
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -51,6 +51,7 @@ files:
51
51
  - lib/types/boolean.rb
52
52
  - lib/types/class.rb
53
53
  - lib/types/decimal.rb
54
+ - lib/types/enumerator.rb
54
55
  - lib/types/float.rb
55
56
  - lib/types/generic.rb
56
57
  - lib/types/hash.rb
metadata.gz.sig CHANGED
Binary file