uinit-type 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uinit/type/composition.rb +2 -2
- data/lib/uinit/type/context.rb +10 -10
- data/lib/uinit/type/generic.rb +1 -1
- data/lib/uinit/type/hash_of.rb +1 -1
- data/lib/uinit/type/type.rb +44 -0
- data/lib/uinit/type/type_of.rb +9 -14
- data/lib/uinit/type/version.rb +1 -1
- data/lib/uinit/type.rb +1 -1
- data/uinit-type.gemspec +1 -1
- metadata +6 -6
- data/lib/uinit/type/instance.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c7881f9a5e13a64bcf4d2ccd9e330403bdd1da330b2794cb97fcb08a85682b2
|
4
|
+
data.tar.gz: 7612f19bf51686197479c68fe7022de018ef5dfad9fddce4159f6cb4a51df0da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/uinit/type/context.rb
CHANGED
@@ -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 =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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,14 +40,14 @@ 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
|
|
47
|
+
def type(type = BasicObject)
|
48
|
+
Type.new(type)
|
49
|
+
end
|
50
|
+
|
51
51
|
def type_of(type)
|
52
52
|
TypeOf.new(type)
|
53
53
|
end
|
data/lib/uinit/type/generic.rb
CHANGED
data/lib/uinit/type/hash_of.rb
CHANGED
@@ -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
|
data/lib/uinit/type/type_of.rb
CHANGED
@@ -3,37 +3,32 @@
|
|
3
3
|
module Uinit
|
4
4
|
module Type
|
5
5
|
class TypeOf < Base
|
6
|
-
def self.from?(
|
7
|
-
|
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(
|
11
|
-
new(
|
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
|
-
|
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
|
-
|
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}
|
31
|
+
type_error!("#{value.inspect} must be an instance of #{class_module}", depth)
|
37
32
|
end
|
38
33
|
|
39
34
|
def inspect
|
data/lib/uinit/type/version.rb
CHANGED
data/lib/uinit/type.rb
CHANGED
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.
|
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-
|
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:
|
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:
|
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:
|
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
|
data/lib/uinit/type/instance.rb
DELETED
@@ -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
|