├── .gitignore ├── .rspec ├── .rubocop.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── Gemfile ├── Gemfile.lock ├── LICENSE.txt ├── README.md ├── Rakefile ├── Steepfile ├── bin ├── console └── setup ├── lib └── smart_core │ ├── type_system.rb │ └── type_system │ ├── errors.rb │ ├── interop.rb │ ├── interop │ ├── abstract_factory.rb │ └── operation.rb │ ├── smart_types.rb │ ├── smart_types │ └── abstract_factory.rb │ └── version.rb ├── sig └── signatures.rbs ├── smart_type-system.gemspec └── spec ├── spec_helper.rb └── units └── version_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | .rspec_status 10 | .ruby-version 11 | *.gem 12 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format progress 2 | --color 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_gem: 2 | armitage-rubocop: 3 | - lib/rubocop.general.yml 4 | - lib/rubocop.rake.yml 5 | - lib/rubocop.rspec.yml 6 | 7 | AllCops: 8 | TargetRubyVersion: 3.0.0 9 | NewCops: enable 10 | Include: 11 | - lib/**/*.rb 12 | - spec/**/*.rb 13 | - Gemfile 14 | - Rakefile 15 | - smart_type-system.gemspec 16 | - bin/console 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 8 | 9 | ## Our Standards 10 | 11 | Examples of behavior that contributes to a positive environment for our community include: 12 | 13 | * Demonstrating empathy and kindness toward other people 14 | * Being respectful of differing opinions, viewpoints, and experiences 15 | * Giving and gracefully accepting constructive feedback 16 | * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 17 | * Focusing on what is best not just for us as individuals, but for the overall community 18 | 19 | Examples of unacceptable behavior include: 20 | 21 | * The use of sexualized language or imagery, and sexual attention or 22 | advances of any kind 23 | * Trolling, insulting or derogatory comments, and personal or political attacks 24 | * Public or private harassment 25 | * Publishing others' private information, such as a physical or email 26 | address, without their explicit permission 27 | * Other conduct which could reasonably be considered inappropriate in a 28 | professional setting 29 | 30 | ## Enforcement Responsibilities 31 | 32 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 33 | 34 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 35 | 36 | ## Scope 37 | 38 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 39 | 40 | ## Enforcement 41 | 42 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at iamdaiver@gmail.com. All complaints will be reviewed and investigated promptly and fairly. 43 | 44 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 45 | 46 | ## Enforcement Guidelines 47 | 48 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 49 | 50 | ### 1. Correction 51 | 52 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 53 | 54 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 55 | 56 | ### 2. Warning 57 | 58 | **Community Impact**: A violation through a single incident or series of actions. 59 | 60 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 61 | 62 | ### 3. Temporary Ban 63 | 64 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 65 | 66 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 67 | 68 | ### 4. Permanent Ban 69 | 70 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 71 | 72 | **Consequence**: A permanent ban from any sort of public interaction within the community. 73 | 74 | ## Attribution 75 | 76 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 77 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 78 | 79 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 80 | 81 | [homepage]: https://www.contributor-covenant.org 82 | 83 | For answers to common questions about this code of conduct, see the FAQ at 84 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 85 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | smart_type-system (0.0.0) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | activesupport (6.1.2.1) 10 | concurrent-ruby (~> 1.0, >= 1.0.2) 11 | i18n (>= 1.6, < 2) 12 | minitest (>= 5.1) 13 | tzinfo (~> 2.0) 14 | zeitwerk (~> 2.3) 15 | armitage-rubocop (1.8.1) 16 | rubocop (= 1.8.1) 17 | rubocop-performance (= 1.9.2) 18 | rubocop-rails (= 2.9.1) 19 | rubocop-rake (= 0.5.1) 20 | rubocop-rspec (= 2.1.0) 21 | ast (2.4.2) 22 | ast_utils (0.4.0) 23 | parser (>= 2.7.0) 24 | coderay (1.1.3) 25 | concurrent-ruby (1.1.8) 26 | diff-lcs (1.4.4) 27 | docile (1.3.5) 28 | ffi (1.14.2) 29 | i18n (1.8.9) 30 | concurrent-ruby (~> 1.0) 31 | language_server-protocol (3.15.0.1) 32 | listen (3.4.1) 33 | rb-fsevent (~> 0.10, >= 0.10.3) 34 | rb-inotify (~> 0.9, >= 0.9.10) 35 | method_source (1.0.0) 36 | minitest (5.14.3) 37 | parallel (1.20.1) 38 | parser (3.0.0.0) 39 | ast (~> 2.4.1) 40 | pry (0.14.0) 41 | coderay (~> 1.1) 42 | method_source (~> 1.0) 43 | rack (2.2.3) 44 | rainbow (3.0.0) 45 | rake (13.0.3) 46 | rb-fsevent (0.10.4) 47 | rb-inotify (0.10.1) 48 | ffi (~> 1.0) 49 | rbs (1.0.5) 50 | regexp_parser (2.0.3) 51 | rexml (3.2.4) 52 | rspec (3.10.0) 53 | rspec-core (~> 3.10.0) 54 | rspec-expectations (~> 3.10.0) 55 | rspec-mocks (~> 3.10.0) 56 | rspec-core (3.10.1) 57 | rspec-support (~> 3.10.0) 58 | rspec-expectations (3.10.1) 59 | diff-lcs (>= 1.2.0, < 2.0) 60 | rspec-support (~> 3.10.0) 61 | rspec-mocks (3.10.2) 62 | diff-lcs (>= 1.2.0, < 2.0) 63 | rspec-support (~> 3.10.0) 64 | rspec-support (3.10.2) 65 | rubocop (1.8.1) 66 | parallel (~> 1.10) 67 | parser (>= 3.0.0.0) 68 | rainbow (>= 2.2.2, < 4.0) 69 | regexp_parser (>= 1.8, < 3.0) 70 | rexml 71 | rubocop-ast (>= 1.2.0, < 2.0) 72 | ruby-progressbar (~> 1.7) 73 | unicode-display_width (>= 1.4.0, < 3.0) 74 | rubocop-ast (1.4.1) 75 | parser (>= 2.7.1.5) 76 | rubocop-performance (1.9.2) 77 | rubocop (>= 0.90.0, < 2.0) 78 | rubocop-ast (>= 0.4.0) 79 | rubocop-rails (2.9.1) 80 | activesupport (>= 4.2.0) 81 | rack (>= 1.1) 82 | rubocop (>= 0.90.0, < 2.0) 83 | rubocop-rake (0.5.1) 84 | rubocop 85 | rubocop-rspec (2.1.0) 86 | rubocop (~> 1.0) 87 | rubocop-ast (>= 1.1.0) 88 | ruby-progressbar (1.11.0) 89 | simplecov (0.21.2) 90 | docile (~> 1.1) 91 | simplecov-html (~> 0.11) 92 | simplecov_json_formatter (~> 0.1) 93 | simplecov-html (0.12.3) 94 | simplecov_json_formatter (0.1.2) 95 | steep (0.41.0) 96 | activesupport (>= 5.1) 97 | ast_utils (>= 0.4.0) 98 | language_server-protocol (~> 3.15.0.1) 99 | listen (~> 3.0) 100 | parser (>= 2.7) 101 | rainbow (>= 2.2.2, < 4.0) 102 | rbs (~> 1.0.3) 103 | tzinfo (2.0.4) 104 | concurrent-ruby (~> 1.0) 105 | unicode-display_width (2.0.0) 106 | zeitwerk (2.4.2) 107 | 108 | PLATFORMS 109 | x86_64-darwin-20 110 | 111 | DEPENDENCIES 112 | armitage-rubocop (~> 1.8) 113 | bundler (~> 2.2) 114 | pry (~> 0.14) 115 | rake (~> 13.0) 116 | rbs (~> 1.0.5) 117 | rspec (~> 3.10) 118 | simplecov (~> 0.21) 119 | smart_type-system! 120 | steep (~> 0.41.0) 121 | 122 | BUNDLED WITH 123 | 2.2.3 124 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021-2024 Rustam Ibragimov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmartCore::TypeSystem · Supported by Cado Labs · [![Gem Version](https://badge.fury.io/rb/smart_engine.svg)](https://badge.fury.io/rb/smart_type-system) 2 | 3 | --- 4 | 5 | *(in active development)* 6 | 7 | --- 8 | 9 |

10 | 11 | Supported by Cado Labs 12 | 13 |

14 | 15 | --- 16 | 17 | ## Installation 18 | 19 | ```ruby 20 | gem 'smart_type-system' 21 | ``` 22 | 23 | ```shell 24 | bundle install 25 | # --- or --- 26 | gem install smart_type-system 27 | ``` 28 | 29 | ```ruby 30 | require 'smart_core/type_system' 31 | ``` 32 | 33 | --- 34 | 35 | ## Contributing 36 | 37 | - Fork it ( https://github.com/smart-rb/smart_type-system/fork ) 38 | - Create your feature branch (`git checkout -b feature/my-new-feature`) 39 | - Commit your changes (`git commit -am '[feature_context] Add some feature'`) 40 | - Push to the branch (`git push origin feature/my-new-feature`) 41 | - Create new Pull Request 42 | 43 | ## License 44 | 45 | Released under MIT License. 46 | 47 | ## Supporting 48 | 49 | 50 | Supported by Cado Labs 51 | 52 | 53 | ## Authors 54 | 55 | [Rustam Ibragimov](https://github.com/0exp) 56 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/gem_tasks' 4 | require 'rspec/core/rake_task' 5 | require 'rubocop' 6 | require 'rubocop/rake_task' 7 | require 'rubocop-performance' 8 | require 'rubocop-rspec' 9 | require 'rubocop-rake' 10 | 11 | RuboCop::RakeTask.new(:rubocop) do |t| 12 | config_path = File.expand_path(File.join('.rubocop.yml'), __dir__) 13 | t.options = ['--config', config_path] 14 | t.requires << 'rubocop-rspec' 15 | t.requires << 'rubocop-performance' 16 | t.requires << 'rubocop-rake' 17 | end 18 | 19 | RSpec::Core::RakeTask.new(:rspec) 20 | 21 | task default: :rspec 22 | -------------------------------------------------------------------------------- /Steepfile: -------------------------------------------------------------------------------- 1 | target :lib do 2 | signature 'sig' 3 | 4 | check 'lib' 5 | end 6 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require 'bundler/setup' 5 | require 'smart_core' 6 | 7 | require 'pry' 8 | Pry.start 9 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /lib/smart_core/type_system.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @api public 4 | # @since 0.1.0 5 | module SmartCore 6 | # @api public 7 | # @since 0.1.0 8 | module TypeSystem 9 | require_relative 'type_system/version' 10 | require_relative 'type_system/errors' 11 | require_relative 'type_system/interop' 12 | require_relative 'type_system/smart_types' 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/smart_core/type_system/errors.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module SmartCore::TypeSystem 4 | end 5 | -------------------------------------------------------------------------------- /lib/smart_core/type_system/interop.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @abstract 4 | # @api private 5 | # @since 0.1.0 6 | class SmartCore::TypeSystem::Interop 7 | require_relative 'interop/operation' 8 | require_relative 'interop/abstract_factory' 9 | 10 | # @param op_valid [SmartCore::TypeSystem::Interop::Operation] 11 | # @param op_validate [SmartCore::TypeSystem::Interop::Operation] 12 | # @param op_cast [SmartCore::TypeSystem::Interop::Operation] 13 | # @return [void] 14 | # 15 | # @api private 16 | # @since 0.1.0 17 | def initialize(op_valid, op_validate, op_cast) 18 | @op_valid = op_valid 19 | @op_validate = op_validate 20 | @op_cast = op_cast 21 | end 22 | 23 | # @param value [Any] 24 | # @return [Any] 25 | # 26 | # @api private 27 | # @since 0.1.0 28 | def cast(value) 29 | op_cast.call(value) 30 | end 31 | 32 | # @return [Boolean] 33 | # 34 | # @api private 35 | # @since 0.1.0 36 | def valid?(value) 37 | op_valid.call(value) 38 | end 39 | 40 | # @return [Any] 41 | # @return [void] 42 | # 43 | # @api private 44 | # @since 0.1.0 45 | def validate!(value) 46 | op_validate.call(value) 47 | end 48 | 49 | private 50 | 51 | # @return [SmartCore::TypeSystem::Interop::Operation] 52 | # 53 | # @api private 54 | # @since 0.1.0 55 | attr_reader :op_valid 56 | 57 | # @return [SmartCore::TypeSystem::Interop::Operation] 58 | # 59 | # @api private 60 | # @since 0.1.0 61 | attr_reader :op_validate 62 | 63 | # @return [SmartCore::TypeSystem::Interop::Operation] 64 | # 65 | # @api private 66 | # @since 0.1.0 67 | attr_reader :op_cast 68 | end 69 | -------------------------------------------------------------------------------- /lib/smart_core/type_system/interop/abstract_factory.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @abstract 4 | # @api private 5 | # @since 0.1.0 6 | class SmartCore::TypeSystem::Interop::AbstractFactory 7 | class << self 8 | # @param type [Any] 9 | # @return [SmartCore::TypeSystem::Interop] 10 | # 11 | # @api private 12 | # @since 0.1.0 13 | def create(type) 14 | prevent_incompatible_type!(type) 15 | 16 | valid_op = build_op_valid(type) 17 | validate_op = build_op_validate(type) 18 | cast_op = build_op_cast(type) 19 | 20 | build_interop(valid_op, validate_op, cast_op) 21 | end 22 | 23 | # @return [Any] 24 | # 25 | # @api private 26 | # @since 0.1.0 27 | def generic_type_object; end 28 | 29 | # @param type [Any] 30 | # @return [void] 31 | # 32 | # @api private 33 | # @since 0.1.0 34 | def prevent_incompatible_type!(type); end 35 | 36 | private 37 | 38 | # @param type [Any] 39 | # @return [SmartCore::TypeSystem::Interop::Operation] 40 | # 41 | # @api private 42 | # @since 0.1.0 43 | def build_op_valid(type); end 44 | 45 | # @param type [Any] 46 | # @return [SmartCore::TypeSystem::Interop::Operation] 47 | # 48 | # @api private 49 | # @since 0.1.0 50 | def build_op_validate(type); end 51 | 52 | # @param type [Any] 53 | # @return [SmartCore::TypeSystem::Interop::Operation] 54 | # 55 | # @api private 56 | # @since 0.1.0 57 | def build_op_cast(type); end 58 | 59 | # @param valid_op [SmartCore::TypeSystem::Interop::Operation] 60 | # @param validate_op [SmartCore::TypeSystem::Interop::Operation] 61 | # @param cast_op [SmartCore::TypeSystem::Interop::Operation] 62 | # @return [SmartCore::TypeSystem::Interop] 63 | # 64 | # @api private 65 | # @since 0.1.0 66 | def build_interop(op_valid, op_validate, op_cast); end 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /lib/smart_core/type_system/interop/operation.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @abstract 4 | # @api private 5 | # @since 0.1.0 6 | class SmartCore::TypeSystem::Interop::Operation 7 | # @param type [SmartCore::TypeSystem::Interop::Type] 8 | # @return [void] 9 | # 10 | # @api private 11 | # @since 0.1.0 12 | def initialize(type) 13 | @type = type 14 | end 15 | 16 | # @param value [Any] 17 | # @return [void] 18 | # 19 | # @api private 20 | # @since 0.1.0 21 | def call(value) 22 | end 23 | 24 | private 25 | 26 | # @return [SmartCore::TypeSystem::Interop::Type] 27 | # 28 | # @api private 29 | # @since 0.1.0 30 | attr_reader :type 31 | end 32 | -------------------------------------------------------------------------------- /lib/smart_core/type_system/smart_types.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # @api public 4 | # @since 0.1.0 5 | class SmartCore::TypeSystem::SmartTypes < SmartCore::TypeSystem::Interop 6 | require_relative 'smart_types/abstract_factory' 7 | end 8 | -------------------------------------------------------------------------------- /lib/smart_core/type_system/smart_types/abstract_factory.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module SmartCore::TypeSystem 4 | # @api private 5 | # @since 0.1.0 6 | class SmartTypes::AbstractFactory < Interop::AbstractFactory 7 | class << self 8 | 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/smart_core/type_system/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module SmartCore 4 | module TypeSystem 5 | # @return [String] 6 | # 7 | # @api private 8 | # @since 0.1.0 9 | VERSION = '0.0.0' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /sig/signatures.rbs: -------------------------------------------------------------------------------- 1 | type interop = SmartCore::TypeSystem::Interop 2 | type interop_op = SmartCore::TypeSystem::Interop::Operation 3 | 4 | interface _TypeOpCast 5 | def call: (untyped value) -> untyped 6 | end 7 | 8 | interface _TypeOpValid 9 | def call: (untyped value) -> bool 10 | end 11 | 12 | interface _TypeOpValidate 13 | def call: (untyped value) -> void 14 | end 15 | 16 | type iop_cast = interop_op & _TypeOpCast 17 | type iop_valid = interop_op & _TypeOpValid 18 | type iop_validate = interop_op & _TypeOpValidate 19 | 20 | module SmartCore 21 | end 22 | 23 | module SmartCore::TypeSystem 24 | VERSION: ::String 25 | end 26 | 27 | class SmartCore::TypeSystem::Interop 28 | def initialize: (iop_valid op_valid, iop_validate op_validate, iop_cast op_cast) -> void 29 | def valid?: (untyped value) -> bool 30 | def validate!: (untyped value) -> void 31 | def cast: (untyped value) -> untyped 32 | 33 | private 34 | 35 | attr_reader op_valid: iop_valid 36 | attr_reader op_validate: iop_validate 37 | attr_reader op_cast: iop_cast 38 | end 39 | 40 | class SmartCore::TypeSystem::Interop::Type 41 | def initialize: (untyped `type`) -> void 42 | 43 | private 44 | 45 | attr_reader `type`: untyped 46 | end 47 | 48 | class SmartCore::TypeSystem::Interop::Operation 49 | def initialize: (untyped `type`) -> void 50 | def call: (untyped value) -> void 51 | 52 | private 53 | 54 | attr_reader `type`: untyped 55 | end 56 | 57 | class SmartCore::TypeSystem::Interop::AbstractFactory 58 | def self.create: (untyped `type`) -> interop? 59 | def self.generic_type_object: () -> untyped 60 | def self.prevent_incompatible_type!: (untyped `type`) -> void 61 | 62 | private 63 | 64 | def self.build_op_valid: (untyped `type`) -> iop_valid? 65 | def self.build_op_validate: (untyped `type`) -> iop_validate? 66 | def self.build_op_cast: (untyped `type`) -> iop_cast? 67 | def self.build_interop: (iop_valid? op_valud, iop_validate? op_validate, iop_cast? op_cast) -> interop? 68 | end 69 | 70 | interface _InteropFactory 71 | def create: (untyped `type`) -> interop 72 | def generic_type_object: () -> untyped 73 | def prevent_incompatible_type!: (untyped `type`) -> void 74 | 75 | def build_op_valid: (untyped `type`) -> iop_valid 76 | def build_op_validate: (untyped `type`) -> iop_validate 77 | def build_op_cast: (untyped `type`) -> iop_cast 78 | def build_interop: (iop_valid op_valud, iop_validate op_validate, iop_cast op_cast) -> interop 79 | end 80 | 81 | class SmartCore::TypeSystem::SmartTypes < SmartCore::TypeSystem::Interop 82 | end 83 | 84 | class SmartCore::TypeSystem::SmartTypes::AbstractFactory < SmartCore::TypeSystem::Interop::AbstractFactory 85 | extend _InteropFactory 86 | end 87 | -------------------------------------------------------------------------------- /smart_type-system.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'lib/smart_core/type_system/version' 4 | 5 | Gem::Specification.new do |spec| 6 | spec.required_ruby_version = Gem::Requirement.new('>= 2.6') 7 | 8 | spec.name = 'smart_type-system' 9 | spec.version = SmartCore::TypeSystem::VERSION 10 | spec.authors = ['Rustam Ibragimov'] 11 | spec.email = ['iamdaiver@gmail.com'] 12 | spec.homepage = 'https://github.com/smart-rb/smart_type-system' 13 | 14 | spec.summary = 'SmartCore::TypeSystem' 15 | spec.description = 'Abstract Type System with a support for various commonly used type libs' 16 | spec.license = 'MIT' 17 | 18 | spec.metadata['homepage_uri'] = spec.homepage 19 | spec.metadata['source_code_uri'] = spec.homepage 20 | spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md" 21 | 22 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 23 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 24 | end 25 | 26 | spec.bindir = 'exe' 27 | spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } 28 | spec.require_paths = ['lib'] 29 | 30 | spec.add_development_dependency 'rbs', '~> 1.0.5' 31 | spec.add_development_dependency 'steep', '~> 0.41.0' 32 | 33 | spec.add_development_dependency 'bundler', '~> 2.2' 34 | spec.add_development_dependency 'rake', '~> 13.0' 35 | spec.add_development_dependency 'rspec', '~> 3.10' 36 | spec.add_development_dependency 'armitage-rubocop', '~> 1.8' 37 | spec.add_development_dependency 'simplecov', '~> 0.21' 38 | spec.add_development_dependency 'pry', '~> 0.14' 39 | end 40 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'simplecov' 4 | 5 | SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter 6 | SimpleCov.minimum_coverage(100) 7 | SimpleCov.enable_coverage(:branch) 8 | SimpleCov.enable_coverage(:line) 9 | SimpleCov.primary_coverage(:line) 10 | SimpleCov.add_filter('spec') 11 | SimpleCov.start 12 | 13 | require 'bundler/setup' 14 | require 'smart_core/type_system' 15 | require 'pry' 16 | 17 | RSpec.configure do |config| 18 | Kernel.srand config.seed 19 | config.disable_monkey_patching! 20 | config.filter_run_when_matching :focus 21 | config.order = :random 22 | config.shared_context_metadata_behavior = :apply_to_host_groups 23 | config.expect_with(:rspec) { |c| c.syntax = :expect } 24 | Thread.abort_on_exception = true 25 | end 26 | -------------------------------------------------------------------------------- /spec/units/version_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe 'Has a version' do 4 | specify { expect(SmartCore::TypeSystem::VERSION).not_to eq(nil) } 5 | end 6 | --------------------------------------------------------------------------------