uinit-type 0.1.0 → 0.1.2

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: c8294bdb922588856e7af78dcd2820da93c237a00cd2db24e90133600610e8ae
4
- data.tar.gz: 173370c0263e2b555b906947fabaa59956ec248b9ce022837b7869069239308e
3
+ metadata.gz: fb64282929e802a3990850303298f7ef0d760a4ba0de2f76238c7fcdae78be34
4
+ data.tar.gz: 56b41392670ebf1a6d75821dc35566efebc76237bc7f40add95a042208b873d4
5
5
  SHA512:
6
- metadata.gz: 0ca2c4d8a705f0e5ef4eb5034355c870b5bb8fc479ce5a652034eb8b956d2350693ad6eaaf59f5ef79fac997c72bfcc92292b7460fbc55f4bce257d82329061c
7
- data.tar.gz: 9cb5b519afd44840f88246be9c1052f3ea37bccd2100b23ff9192ad2ef3f0ebf931783fa1bf6de1f698035d5ce1fe6e8a3b67e3a90875594f01a720c6a681797
6
+ metadata.gz: 40959dc6b5d6eb837add87f3773d0b68bbb5763793454ec0a5efed2bb97a3a664e0fed858d35afc05b9729e32bc439ec59019c2cfca778a6bb2806d61ebedd36
7
+ data.tar.gz: cbc772cc6614ca3c8ad07293d3e0f0f50be232e6d7b85e35beeda0352a61b945fb9485e88f2e50bc16650f5b0a37c9b0bb0c15ce51437d243a06a019629ec830
data/README.md CHANGED
@@ -1,35 +1,7 @@
1
1
  # Uinit::Type
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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
- ## Installation
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)
@@ -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 typeof(type)
52
+ TypeOf.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 TypeOf < 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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Uinit
4
4
  module Type
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.2'
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, Const].find do |type_class|
24
+ [Base, Instance, ArrayOf, SetOf, HashOf, Check, TypeOf, Const].find do |type_class|
25
25
  type_class.from?(arg)
26
26
  end
27
27
 
@@ -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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kimoja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-08 00:00:00.000000000 Z
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
@@ -106,7 +120,9 @@ files:
106
120
  - lib/uinit/type/instance.rb
107
121
  - lib/uinit/type/operators.rb
108
122
  - lib/uinit/type/set_of.rb
123
+ - lib/uinit/type/type_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