uinit-type 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -31
- data/lib/uinit/type/context.rb +9 -0
- data/lib/uinit/type/extend.rb +44 -0
- data/lib/uinit/type/version.rb +1 -1
- data/uinit-type.gemspec +37 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31a74587cea1d8bbf1d3e6e5d29850303c6ce319fadb0f9c6967d278040d12be
|
4
|
+
data.tar.gz: d671e387cc6793656a9f5b32c30aa5db37c6b9606df883b7c5788f9f72174361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a461fa8a15247c09336a8b4342f437e28ba509ca5ca00765abe77fe5c503804bf05797aa749bbe52cd4d67040c7e2306a468f2a16d68aef0122cb65ae022fd7a
|
7
|
+
data.tar.gz: 74aa457314cedb6ad1d9545112b2aae6cbeee66e47323e7d118386b7907b9e2accd4f8c41b2d036a91ee67faf3c817ea946709c809c6aa5cd106c03cd93f7705
|
data/README.md
CHANGED
@@ -1,35 +1,7 @@
|
|
1
1
|
# Uinit::Type
|
2
2
|
|
3
|
-
|
3
|
+
Dynamic type checker
|
4
4
|
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/uinit/type`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
5
|
|
7
|
-
##
|
8
|
-
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
12
|
-
|
13
|
-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
14
|
-
|
15
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
-
|
17
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Development
|
24
|
-
|
25
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
-
|
27
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
-
|
29
|
-
## Contributing
|
30
|
-
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/uinit-type.
|
32
|
-
|
33
|
-
## License
|
34
|
-
|
35
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
6
|
+
## TODO
|
7
|
+
- type Map, an generic hash (key, value types)
|
data/lib/uinit/type/context.rb
CHANGED
@@ -10,6 +10,7 @@ module Uinit
|
|
10
10
|
Float = Instance[Float].freeze
|
11
11
|
Hsh = Instance[Hash].freeze
|
12
12
|
Arr = Instance[Array].freeze
|
13
|
+
Sym = Instance[Symbol].freeze
|
13
14
|
|
14
15
|
def array_of(type)
|
15
16
|
ArrayOf.new(type)
|
@@ -47,6 +48,10 @@ module Uinit
|
|
47
48
|
SetOf.new(type)
|
48
49
|
end
|
49
50
|
|
51
|
+
def extends(type)
|
52
|
+
Extend.new(type)
|
53
|
+
end
|
54
|
+
|
50
55
|
def nilable
|
51
56
|
Nil
|
52
57
|
end
|
@@ -79,6 +84,10 @@ module Uinit
|
|
79
84
|
def array
|
80
85
|
Arr
|
81
86
|
end
|
87
|
+
|
88
|
+
def sym
|
89
|
+
Sym
|
90
|
+
end
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Uinit
|
4
|
+
module Type
|
5
|
+
class Extend < 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 #{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/version.rb
CHANGED
data/uinit-type.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'uinit/type/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'uinit-type'
|
10
|
+
spec.version = Uinit::Type::VERSION
|
11
|
+
spec.authors = ['Kimoja']
|
12
|
+
spec.email = ['joakim.carrilho@cheerz.com']
|
13
|
+
|
14
|
+
spec.summary = 'Dynamic type checker'
|
15
|
+
spec.description = 'Dynamic type checker'
|
16
|
+
spec.homepage = 'https://github.com/Kimoja/uinit-type'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
spec.required_ruby_version = '>= 3.2.1'
|
19
|
+
spec.files = Dir['CHANGELOG.md', 'LICENSE.txt', 'README.md', 'uinit-type.gemspec', 'lib/**/*']
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.executables = []
|
22
|
+
|
23
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
24
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
25
|
+
spec.metadata['source_code_uri'] = 'https://github.com/Kimoja/uinit-type'
|
26
|
+
spec.metadata['changelog_uri'] = 'https://github.com/Kimoja/uinit-type/blob/main/CHANGELOG.md'
|
27
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/Kimoja/uinit-type/issues'
|
28
|
+
|
29
|
+
spec.add_runtime_dependency 'zeitwerk', '~> 2.6'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler'
|
32
|
+
spec.add_development_dependency 'pry'
|
33
|
+
spec.add_development_dependency 'rspec'
|
34
|
+
spec.add_development_dependency 'rubocop'
|
35
|
+
spec.add_development_dependency 'rake'
|
36
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kimoja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Dynamic type checker
|
84
98
|
email:
|
85
99
|
- joakim.carrilho@cheerz.com
|
@@ -98,6 +112,7 @@ files:
|
|
98
112
|
- lib/uinit/type/const.rb
|
99
113
|
- lib/uinit/type/context.rb
|
100
114
|
- lib/uinit/type/error.rb
|
115
|
+
- lib/uinit/type/extend.rb
|
101
116
|
- lib/uinit/type/extensions.rb
|
102
117
|
- lib/uinit/type/fn.rb
|
103
118
|
- lib/uinit/type/generic.rb
|
@@ -107,6 +122,7 @@ files:
|
|
107
122
|
- lib/uinit/type/operators.rb
|
108
123
|
- lib/uinit/type/set_of.rb
|
109
124
|
- lib/uinit/type/version.rb
|
125
|
+
- uinit-type.gemspec
|
110
126
|
homepage: https://github.com/Kimoja/uinit-type
|
111
127
|
licenses:
|
112
128
|
- MIT
|