uinit-type 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb64282929e802a3990850303298f7ef0d760a4ba0de2f76238c7fcdae78be34
4
- data.tar.gz: 56b41392670ebf1a6d75821dc35566efebc76237bc7f40add95a042208b873d4
3
+ metadata.gz: 2c7881f9a5e13a64bcf4d2ccd9e330403bdd1da330b2794cb97fcb08a85682b2
4
+ data.tar.gz: 7612f19bf51686197479c68fe7022de018ef5dfad9fddce4159f6cb4a51df0da
5
5
  SHA512:
6
- metadata.gz: 40959dc6b5d6eb837add87f3773d0b68bbb5763793454ec0a5efed2bb97a3a664e0fed858d35afc05b9729e32bc439ec59019c2cfca778a6bb2806d61ebedd36
7
- data.tar.gz: cbc772cc6614ca3c8ad07293d3e0f0f50be232e6d7b85e35beeda0352a61b945fb9485e88f2e50bc16650f5b0a37c9b0bb0c15ce51437d243a06a019629ec830
6
+ metadata.gz: bf8e5041e730686dbaa48ed891d4363aa36c4d88515b9a263db7aed593d60fac3fd3601a672d961a6ab6be6674381ccca632848c82ca9bc18e6c918cffff352e
7
+ data.tar.gz: befcdcc0f310459d63b5bfe72cadcc8c9a94bc10898f1bd6de61839a7d82188dfe5f72adba38a3b3cd15dda28bbf21ad6cd30059b06295220b9ac9531a1536d7
@@ -9,7 +9,7 @@ module Uinit
9
9
  def initialize(operand, compositions = [])
10
10
  super()
11
11
 
12
- @operand = Type.from(operand)
12
+ @operand = ::Uinit::Type.from(operand)
13
13
  @compositions = compositions
14
14
  end
15
15
 
@@ -86,7 +86,7 @@ module Uinit
86
86
  private
87
87
 
88
88
  def add_composition(operator, operand)
89
- compositions << [operator, Type.from(operand)]
89
+ compositions << [operator, ::Uinit::Type.from(operand)]
90
90
 
91
91
  self
92
92
  end
@@ -5,12 +5,12 @@ module Uinit
5
5
  module Context
6
6
  Nil = Const[nil].freeze
7
7
  Boolean = (Const[true] | Const[false]).freeze
8
- Str = Instance[String].freeze
9
- Int = Instance[Integer].freeze
10
- Float = Instance[Float].freeze
11
- Hsh = Instance[Hash].freeze
12
- Arr = Instance[Array].freeze
13
- Sym = Instance[Symbol].freeze
8
+ Str = TypeOf[String].freeze
9
+ Sym = TypeOf[Symbol].freeze
10
+ Int = TypeOf[Integer].freeze
11
+ Float = TypeOf[Float].freeze
12
+ Hsh = TypeOf[Hash].freeze
13
+ Arr = TypeOf[Array].freeze
14
14
 
15
15
  def array_of(type)
16
16
  ArrayOf.new(type)
@@ -40,15 +40,15 @@ module Uinit
40
40
  Impl.new(*, **)
41
41
  end
42
42
 
43
- def instance(type)
44
- Instance.new(type)
45
- end
46
-
47
43
  def set_of(type) # rubocop:disable Naming/AccessorMethodName
48
44
  SetOf.new(type)
49
45
  end
50
46
 
51
- def typeof(type)
47
+ def type(type = BasicObject)
48
+ Type.new(type)
49
+ end
50
+
51
+ def type_of(type)
52
52
  TypeOf.new(type)
53
53
  end
54
54
 
@@ -6,7 +6,7 @@ module Uinit
6
6
  def initialize(type)
7
7
  super()
8
8
 
9
- @type = Type.from(type)
9
+ @type = ::Uinit::Type.from(type)
10
10
  end
11
11
 
12
12
  attr_reader :type
@@ -18,7 +18,7 @@ module Uinit
18
18
 
19
19
  @schema =
20
20
  schema.transform_values do |type|
21
- Type.from(type)
21
+ ::Uinit::Type.from(type)
22
22
  end
23
23
 
24
24
  @strict = !!strict
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uinit
4
+ module Type
5
+ class Type < Base
6
+ def self.from?(value)
7
+ value.is_a?(Class) || value.is_a?(Module)
8
+ end
9
+
10
+ def self.from(value)
11
+ new(value) if from?(value)
12
+ end
13
+
14
+ # TODO: Allow to pass Fn
15
+ def initialize(class_module)
16
+ super()
17
+
18
+ @class_module = class_module
19
+ end
20
+
21
+ attr_reader :class_module
22
+
23
+ def is?(value)
24
+ return false unless value.is_a?(Class) || value.is_a?(Module)
25
+
26
+ value.ancestors.include?(class_module)
27
+ end
28
+
29
+ def check!(value, depth)
30
+ unless value.is_a?(Class) || value.is_a?(Module)
31
+ type_error!("#{value.inspect} is not a Class or a Module", depth)
32
+ end
33
+
34
+ return value if value.ancestors.include?(class_module)
35
+
36
+ type_error!("#{value.inspect} does not extend or include or preprend #{class_module}", depth)
37
+ end
38
+
39
+ def inspect
40
+ "#{super}[#{class_module.inspect}]"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -3,37 +3,32 @@
3
3
  module Uinit
4
4
  module Type
5
5
  class TypeOf < Base
6
- def self.from?(value)
7
- value.is_a?(Class) || value.is_a?(Module)
6
+ def self.from?(class_module)
7
+ class_module.is_a?(::Class) || class_module.is_a?(::Module)
8
8
  end
9
9
 
10
- def self.from(value)
11
- new(value) if from?(value)
10
+ def self.from(class_module)
11
+ new(class_module) if from?(class_module)
12
12
  end
13
13
 
14
- # TODO: Allow to pass Fn
15
14
  def initialize(class_module)
16
15
  super()
17
16
 
17
+ raise ArgumentError, 'class_module must be a Class or a Module' unless self.class.from?(class_module)
18
+
18
19
  @class_module = class_module
19
20
  end
20
21
 
21
22
  attr_reader :class_module
22
23
 
23
24
  def is?(value)
24
- return false unless value.is_a?(Class) || value.is_a?(Module)
25
-
26
- value.ancestors.include?(class_module)
25
+ value.is_a?(class_module)
27
26
  end
28
27
 
29
28
  def check!(value, depth)
30
- unless value.is_a?(Class) || value.is_a?(Module)
31
- type_error!("#{value.inspect} is not a Class or a Module", depth)
32
- end
33
-
34
- return value if value.ancestors.include?(class_module)
29
+ return value if is?(value)
35
30
 
36
- type_error!("#{value.inspect} does not extend or include or preprend #{class_module}", depth)
31
+ type_error!("#{value.inspect} must be an instance of #{class_module}", depth)
37
32
  end
38
33
 
39
34
  def inspect
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Uinit
4
4
  module Type
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.4'
6
6
  end
7
7
  end
data/lib/uinit/type.rb CHANGED
@@ -21,7 +21,7 @@ module Uinit
21
21
 
22
22
  def self.from(arg)
23
23
  klass =
24
- [Base, Instance, ArrayOf, SetOf, HashOf, Check, TypeOf, Const].find do |type_class|
24
+ [Base, TypeOf, ArrayOf, SetOf, HashOf, Check, Type, Const].find do |type_class|
25
25
  type_class.from?(arg)
26
26
  end
27
27
 
data/uinit-type.gemspec CHANGED
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_development_dependency 'bundler'
32
32
  spec.add_development_dependency 'pry'
33
+ spec.add_development_dependency 'rake'
33
34
  spec.add_development_dependency 'rspec'
34
35
  spec.add_development_dependency 'rubocop'
35
- spec.add_development_dependency 'rake'
36
36
  spec.metadata['rubygems_mfa_required'] = 'true'
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uinit-type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kimoja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-18 00:00:00.000000000 Z
11
+ date: 2024-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rake
84
+ name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -117,9 +117,9 @@ files:
117
117
  - lib/uinit/type/generic.rb
118
118
  - lib/uinit/type/hash_of.rb
119
119
  - lib/uinit/type/impl.rb
120
- - lib/uinit/type/instance.rb
121
120
  - lib/uinit/type/operators.rb
122
121
  - lib/uinit/type/set_of.rb
122
+ - lib/uinit/type/type.rb
123
123
  - lib/uinit/type/type_of.rb
124
124
  - lib/uinit/type/version.rb
125
125
  - uinit-type.gemspec
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Uinit
4
- module Type
5
- class Instance < Base
6
- def self.from?(class_module)
7
- class_module.is_a?(::Class) || class_module.is_a?(::Module)
8
- end
9
-
10
- def self.from(class_module)
11
- new(class_module) if from?(class_module)
12
- end
13
-
14
- def initialize(class_module)
15
- super()
16
-
17
- raise ArgumentError, 'class_module must be a Class or a Module' unless self.class.from?(class_module)
18
-
19
- @class_module = class_module
20
- end
21
-
22
- attr_reader :class_module
23
-
24
- def is?(value)
25
- value.is_a?(class_module)
26
- end
27
-
28
- def check!(value, depth)
29
- return value if is?(value)
30
-
31
- type_error!("#{value.inspect} must be an instance of #{class_module}", depth)
32
- end
33
-
34
- def inspect
35
- "#{super}[#{class_module.inspect}]"
36
- end
37
- end
38
- end
39
- end