rubyt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rubyt.rb +13 -0
- data/lib/types/any.rb +43 -0
- data/lib/types/array_t.rb +46 -0
- data/lib/types/boolean.rb +41 -0
- data/lib/types/errors/rubyt_error.rb +3 -0
- data/lib/types/errors/rubyt_must_not_be_nil_error.rb +7 -0
- data/lib/types/errors/rubyt_type_error.rb +7 -0
- data/lib/types/false.rb +38 -0
- data/lib/types/float_t.rb +38 -0
- data/lib/types/hash_t.rb +38 -0
- data/lib/types/integer_t.rb +38 -0
- data/lib/types/monkey_patching/object.rb +9 -0
- data/lib/types/nil.rb +38 -0
- data/lib/types/nilable_string.rb +41 -0
- data/lib/types/string_t.rb +55 -0
- data/lib/types/true.rb +38 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a2ecb70611af5d3e5bcb3d5ac63a0fd27cc39c33d453cf6a2d352fd957869f7
|
4
|
+
data.tar.gz: b6fdfd529f5bec54ea93190d5853e83c195e02b74241656309c29a8efd9683de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 060d617265a9c61cdcaebb60dff372439d97946fb5ab31fd149cadcb4b843fcef9f60dad172554af1057025a530f54bc785526334ccf70806bd0230de7650944
|
7
|
+
data.tar.gz: af722516b47c3fb5ed5f5e76821f6ec975b48d876f81af757acc2744d4934853518baad1562c61bbb9ebf5b7c708535219a8611809ddaaddab11ddbe710c63e6
|
data/lib/rubyt.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Rubyt v0.0.1
|
4
|
+
|
5
|
+
require_relative 'types/monkey_patching/object'
|
6
|
+
require_relative 'types/any'
|
7
|
+
require_relative 'types/array_t'
|
8
|
+
require_relative 'types/boolean'
|
9
|
+
require_relative 'types/float_t'
|
10
|
+
require_relative 'types/hash_t'
|
11
|
+
require_relative 'types/integer_t'
|
12
|
+
require_relative 'types/nilable_string'
|
13
|
+
require_relative 'types/string_t'
|
data/lib/types/any.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'errors/rubyt_type_error'
|
4
|
+
|
5
|
+
class Any
|
6
|
+
class << self
|
7
|
+
def t(value)
|
8
|
+
raise RubytTypeError.new(Any, value.class) unless value.is_a? Any
|
9
|
+
|
10
|
+
value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def valid_value?(value); end
|
17
|
+
|
18
|
+
def validate_value(value); end
|
19
|
+
|
20
|
+
def setup_value(value)
|
21
|
+
if value.is_a? Any
|
22
|
+
validate_value(value.t)
|
23
|
+
|
24
|
+
return value.t
|
25
|
+
end
|
26
|
+
|
27
|
+
validate_value(value)
|
28
|
+
|
29
|
+
value
|
30
|
+
end
|
31
|
+
|
32
|
+
public
|
33
|
+
|
34
|
+
def initialize(value = nil) = @value = setup_value(value)
|
35
|
+
|
36
|
+
def t = @value
|
37
|
+
|
38
|
+
def t=(value)
|
39
|
+
@value = setup_value(value)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s = @value.to_s
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class ArrayT < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(ArrayT, value.class) unless value.is_a? ArrayT
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value) = value.is_a? Array
|
18
|
+
|
19
|
+
def validate_value(value)
|
20
|
+
raise RubytTypeError.new(Array, value.class) unless valid_value? value
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_value(value)
|
24
|
+
if value.is_a? ArrayT
|
25
|
+
validate_value(value.t)
|
26
|
+
|
27
|
+
return value.t
|
28
|
+
end
|
29
|
+
|
30
|
+
validate_value(value)
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
public
|
36
|
+
|
37
|
+
def initialize(value) = super(setup_value(value))
|
38
|
+
|
39
|
+
def ==(other)
|
40
|
+
other.is_a?(ArrayT) && other.t == @value
|
41
|
+
end
|
42
|
+
|
43
|
+
def !=(other)
|
44
|
+
!(other.is_a?(ArrayT) && other.t == @value)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class Boolean < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(Boolean, value.class) unless value.is_a? Boolean
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value)
|
18
|
+
valid_classes = [TrueClass, FalseClass]
|
19
|
+
valid_classes.include? value.class
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate_value(value)
|
23
|
+
raise RubytTypeError.new('TrueClass or FalseClass', value.class) unless valid_value? value
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup_value(value)
|
27
|
+
if value.is_a? Boolean
|
28
|
+
validate_value(value.t)
|
29
|
+
|
30
|
+
return value.t
|
31
|
+
end
|
32
|
+
|
33
|
+
validate_value(value)
|
34
|
+
|
35
|
+
value
|
36
|
+
end
|
37
|
+
|
38
|
+
public
|
39
|
+
|
40
|
+
def initialize(value) = super(setup_value(value))
|
41
|
+
end
|
data/lib/types/false.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class False < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(False, value.class) unless value.is_a? False
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value) = value.is_a? FalseClass
|
18
|
+
|
19
|
+
def validate_value(value)
|
20
|
+
raise RubytTypeError.new(FalseClass, value.class) unless valid_value? value
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_value(value)
|
24
|
+
if value.is_a? False
|
25
|
+
validate_value(value.t)
|
26
|
+
|
27
|
+
return value.t
|
28
|
+
end
|
29
|
+
|
30
|
+
validate_value(value)
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
public
|
36
|
+
|
37
|
+
def initialize(value) = super(setup_value(value))
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class FloatT < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(FloatT, value.class) unless value.is_a? FloatT
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value) = value.is_a? Float
|
18
|
+
|
19
|
+
def validate_value(value)
|
20
|
+
raise RubytTypeError.new(Float, value.class) unless valid_value? value
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_value(value)
|
24
|
+
if value.is_a? FloatT
|
25
|
+
validate_value(value.t)
|
26
|
+
|
27
|
+
return value.t
|
28
|
+
end
|
29
|
+
|
30
|
+
validate_value(value)
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
public
|
36
|
+
|
37
|
+
def initialize(value) = super(setup_value(value))
|
38
|
+
end
|
data/lib/types/hash_t.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class HashT < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(HashT, value.class) unless value.is_a? HashT
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value) = value.is_a? Hash
|
18
|
+
|
19
|
+
def validate_value(value)
|
20
|
+
raise RubytTypeError.new(Hash, value.class) unless valid_value? value
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_value(value)
|
24
|
+
if value.is_a? HashT
|
25
|
+
validate_value(value.t)
|
26
|
+
|
27
|
+
return value.t
|
28
|
+
end
|
29
|
+
|
30
|
+
validate_value(value)
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
public
|
36
|
+
|
37
|
+
def initialize(value) = super(setup_value(value))
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class IntegerT < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(IntegerT, value.class) unless value.is_a? IntegerT
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value) = value.is_a? Integer
|
18
|
+
|
19
|
+
def validate_value(value)
|
20
|
+
raise RubytTypeError.new(Integer, value.class) unless valid_value? value
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_value(value)
|
24
|
+
if value.is_a? IntegerT
|
25
|
+
validate_value(value.t)
|
26
|
+
|
27
|
+
return value.t
|
28
|
+
end
|
29
|
+
|
30
|
+
validate_value(value)
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
public
|
36
|
+
|
37
|
+
def initialize(value) = super(setup_value(value))
|
38
|
+
end
|
data/lib/types/nil.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class Nil < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(Nil, value.class) unless value.is_a? Nil
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value) = value.is_a? NilClass
|
18
|
+
|
19
|
+
def validate_value(value)
|
20
|
+
raise RubytTypeError.new(NilClass, value.class) unless valid_value? value
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_value(value)
|
24
|
+
if value.is_a? Nil
|
25
|
+
validate_value(value.t)
|
26
|
+
|
27
|
+
return value.t
|
28
|
+
end
|
29
|
+
|
30
|
+
validate_value(value)
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
public
|
36
|
+
|
37
|
+
def initialize(value = nil) = super(setup_value(value))
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class NilableString < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(NilableString, value.class) unless value.is_a? NilableString
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value)
|
18
|
+
valid_classes = [NilClass, String]
|
19
|
+
valid_classes.include? value.class
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate_value(value)
|
23
|
+
raise RubytTypeError.new('NilClass or String', value.class) unless valid_value? value
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup_value(value)
|
27
|
+
if value.is_a? NilableString
|
28
|
+
validate_value(value.t)
|
29
|
+
|
30
|
+
return value.t
|
31
|
+
end
|
32
|
+
|
33
|
+
validate_value(value)
|
34
|
+
|
35
|
+
value
|
36
|
+
end
|
37
|
+
|
38
|
+
public
|
39
|
+
|
40
|
+
def initialize(value = nil) = super(setup_value(value))
|
41
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'array_t'
|
5
|
+
require_relative 'errors/rubyt_type_error'
|
6
|
+
|
7
|
+
class StringT < Any
|
8
|
+
class << self
|
9
|
+
def t(*values)
|
10
|
+
validated_values = ArrayT.new(
|
11
|
+
values.map do |value|
|
12
|
+
raise RubytTypeError.new(StringT, value.class) unless value.is_a? StringT
|
13
|
+
|
14
|
+
value
|
15
|
+
end
|
16
|
+
)
|
17
|
+
|
18
|
+
return validated_values.t.first if validated_values.t.length == 1
|
19
|
+
|
20
|
+
validated_values
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def valid_value?(value) = value.is_a? String
|
27
|
+
|
28
|
+
def validate_value(value)
|
29
|
+
raise RubytTypeError.new(String, value.class) unless valid_value? value
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup_value(value)
|
33
|
+
if value.is_a? StringT
|
34
|
+
validate_value(value.t)
|
35
|
+
|
36
|
+
return value.t
|
37
|
+
end
|
38
|
+
|
39
|
+
validate_value(value)
|
40
|
+
|
41
|
+
value
|
42
|
+
end
|
43
|
+
|
44
|
+
public
|
45
|
+
|
46
|
+
def initialize(value) = super(setup_value(value))
|
47
|
+
|
48
|
+
def ==(other)
|
49
|
+
other.is_a?(StringT) && other.t == @value
|
50
|
+
end
|
51
|
+
|
52
|
+
def !=(other)
|
53
|
+
!(other.is_a?(StringT) && other.t == @value)
|
54
|
+
end
|
55
|
+
end
|
data/lib/types/true.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'any'
|
4
|
+
require_relative 'errors/rubyt_type_error'
|
5
|
+
|
6
|
+
class True < Any
|
7
|
+
class << self
|
8
|
+
def t(value)
|
9
|
+
raise RubytTypeError.new(True, value.class) unless value.is_a? True
|
10
|
+
|
11
|
+
value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def valid_value?(value) = value.is_a? TrueClass
|
18
|
+
|
19
|
+
def validate_value(value)
|
20
|
+
raise RubytTypeError.new(TrueClass, value.class) unless valid_value? value
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_value(value)
|
24
|
+
if value.is_a? True
|
25
|
+
validate_value(value.t)
|
26
|
+
|
27
|
+
return value.t
|
28
|
+
end
|
29
|
+
|
30
|
+
validate_value(value)
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
|
35
|
+
public
|
36
|
+
|
37
|
+
def initialize(value) = super(setup_value(value))
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ZaikoXander
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Rubyt is a ruby gem that provides type checking functionality. It includes
|
14
|
+
support for various types such as Boolean, Integer, String, Array, Hash and more.
|
15
|
+
This gem is designed to enforce type safety, facilitating the creation of readable
|
16
|
+
and maintainable code. It includes custom error handling for type mismatches. With
|
17
|
+
its ease of use and integration, it can seamlessly fit into existing projects.
|
18
|
+
email:
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- lib/rubyt.rb
|
24
|
+
- lib/types/any.rb
|
25
|
+
- lib/types/array_t.rb
|
26
|
+
- lib/types/boolean.rb
|
27
|
+
- lib/types/errors/rubyt_error.rb
|
28
|
+
- lib/types/errors/rubyt_must_not_be_nil_error.rb
|
29
|
+
- lib/types/errors/rubyt_type_error.rb
|
30
|
+
- lib/types/false.rb
|
31
|
+
- lib/types/float_t.rb
|
32
|
+
- lib/types/hash_t.rb
|
33
|
+
- lib/types/integer_t.rb
|
34
|
+
- lib/types/monkey_patching/object.rb
|
35
|
+
- lib/types/nil.rb
|
36
|
+
- lib/types/nilable_string.rb
|
37
|
+
- lib/types/string_t.rb
|
38
|
+
- lib/types/true.rb
|
39
|
+
homepage: https://github.com/ZaikoXander/rubyt
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
rubygems_mfa_required: 'true'
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.2.2
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.4.10
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: A ruby type checking gem
|
63
|
+
test_files: []
|