smart_types 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +15 -0
  5. data/.travis.yml +20 -0
  6. data/CHANGELOG.md +2 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +5 -0
  9. data/Gemfile.lock +77 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +85 -0
  12. data/Rakefile +21 -0
  13. data/bin/console +8 -0
  14. data/bin/setup +8 -0
  15. data/lib/smart_core/types.rb +13 -0
  16. data/lib/smart_core/types/errors.rb +27 -0
  17. data/lib/smart_core/types/primitive.rb +76 -0
  18. data/lib/smart_core/types/primitive/caster.rb +31 -0
  19. data/lib/smart_core/types/primitive/checker.rb +31 -0
  20. data/lib/smart_core/types/primitive/factory.rb +96 -0
  21. data/lib/smart_core/types/primitive/factory/definition_context.rb +46 -0
  22. data/lib/smart_core/types/primitive/mult_checker.rb +31 -0
  23. data/lib/smart_core/types/primitive/mult_factory.rb +69 -0
  24. data/lib/smart_core/types/primitive/mult_factory/definition_context.rb +29 -0
  25. data/lib/smart_core/types/primitive/sum_checker.rb +31 -0
  26. data/lib/smart_core/types/primitive/sum_factory.rb +69 -0
  27. data/lib/smart_core/types/primitive/sum_factory/definition_context.rb +29 -0
  28. data/lib/smart_core/types/primitive/undefined_caster.rb +19 -0
  29. data/lib/smart_core/types/system.rb +7 -0
  30. data/lib/smart_core/types/system/producer_dsl.rb +30 -0
  31. data/lib/smart_core/types/value.rb +19 -0
  32. data/lib/smart_core/types/value/any.rb +14 -0
  33. data/lib/smart_core/types/value/array.rb +17 -0
  34. data/lib/smart_core/types/value/boolean.rb +9 -0
  35. data/lib/smart_core/types/value/class.rb +9 -0
  36. data/lib/smart_core/types/value/float.rb +17 -0
  37. data/lib/smart_core/types/value/hash.rb +17 -0
  38. data/lib/smart_core/types/value/integer.rb +17 -0
  39. data/lib/smart_core/types/value/module.rb +9 -0
  40. data/lib/smart_core/types/value/numeric.rb +17 -0
  41. data/lib/smart_core/types/value/proc.rb +11 -0
  42. data/lib/smart_core/types/value/string.rb +11 -0
  43. data/lib/smart_core/types/value/symbol.rb +11 -0
  44. data/lib/smart_core/types/value/text.rb +11 -0
  45. data/lib/smart_core/types/version.rb +11 -0
  46. data/smart_types.gemspec +42 -0
  47. metadata +178 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0947505b9b53b32bdbe16484fd2f3649164ea15afbc563a66f9b4b057b4101a3'
4
+ data.tar.gz: 33808e34bdf040f9ff38d9a14c904981500beee5520e3bfc54f398a2b94adf65
5
+ SHA512:
6
+ metadata.gz: 62ae3a3710966f62d31998a39272029189a13ec3b0cafb64409a8a79c6ab314d70c1efaab14fc0de7f6dc60abdc82e12a5abfd3c6a82eb05949e06bf0289b825
7
+ data.tar.gz: '08234057dcb0626c8eee23395bb6eb3aa68b7186928faf397410f2fa48a39944b1671846bd09ae6a2038834f3d14b1f966d7089554ce03af458079d1c4d2b1a3'
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rspec_status
10
+ /.idea
11
+ .ruby-version
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,15 @@
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: 2.4.9
9
+ Include:
10
+ - lib/**/*.rb
11
+ - spec/**/*.rb
12
+ - Gemfile
13
+ - Rakefile
14
+ - smart_types.gemspec
15
+ - bin/console
@@ -0,0 +1,20 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ os: linux
5
+ before_install: gem install bundler -v 2.1.2
6
+ script:
7
+ - bundle exec rake rubocop
8
+ - bundle exec rake rspec
9
+ jobs:
10
+ fast_finish: true
11
+ include:
12
+ - rvm: 2.4.9
13
+ - rvm: 2.5.7
14
+ - rvm: 2.6.5
15
+ - rvm: 2.7.0
16
+ - rvm: ruby-head
17
+ - rvm: jruby-head
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
@@ -0,0 +1,2 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at iamdaiver@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ smart_types (0.1.0)
5
+ smart_engine (~> 0.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ armitage-rubocop (0.79.0)
11
+ rubocop (= 0.79.0)
12
+ rubocop-performance (= 1.5.2)
13
+ rubocop-rails (= 2.4.1)
14
+ rubocop-rake (= 0.5.0)
15
+ rubocop-rspec (= 1.37.1)
16
+ ast (2.4.0)
17
+ diff-lcs (1.3)
18
+ docile (1.3.2)
19
+ jaro_winkler (1.5.4)
20
+ json (2.3.0)
21
+ parallel (1.19.1)
22
+ parser (2.7.0.2)
23
+ ast (~> 2.4.0)
24
+ rack (2.1.1)
25
+ rainbow (3.0.0)
26
+ rake (13.0.1)
27
+ rspec (3.9.0)
28
+ rspec-core (~> 3.9.0)
29
+ rspec-expectations (~> 3.9.0)
30
+ rspec-mocks (~> 3.9.0)
31
+ rspec-core (3.9.1)
32
+ rspec-support (~> 3.9.1)
33
+ rspec-expectations (3.9.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.9.0)
36
+ rspec-mocks (3.9.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-support (3.9.2)
40
+ rubocop (0.79.0)
41
+ jaro_winkler (~> 1.5.1)
42
+ parallel (~> 1.10)
43
+ parser (>= 2.7.0.1)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 1.4.0, < 1.7)
47
+ rubocop-performance (1.5.2)
48
+ rubocop (>= 0.71.0)
49
+ rubocop-rails (2.4.1)
50
+ rack (>= 1.1)
51
+ rubocop (>= 0.72.0)
52
+ rubocop-rake (0.5.0)
53
+ rubocop
54
+ rubocop-rspec (1.37.1)
55
+ rubocop (>= 0.68.1)
56
+ ruby-progressbar (1.10.1)
57
+ simplecov (0.17.1)
58
+ docile (~> 1.1)
59
+ json (>= 1.8, < 3)
60
+ simplecov-html (~> 0.10.0)
61
+ simplecov-html (0.10.2)
62
+ smart_engine (0.3.0)
63
+ unicode-display_width (1.6.0)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ armitage-rubocop (~> 0.78)
70
+ bundler (~> 2.1)
71
+ rake (~> 13.0)
72
+ rspec (~> 3.9)
73
+ simplecov (~> 0.17)
74
+ smart_types!
75
+
76
+ BUNDLED WITH
77
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 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.
@@ -0,0 +1,85 @@
1
+ # SmartCore::Types &middot; [![Gem Version](https://badge.fury.io/rb/smart_types.svg)](https://badge.fury.io/rb/smart_types) [![Build Status](https://travis-ci.org/smart-rb/smart_types.svg?branch=master)](https://travis-ci.org/smart-rb/smart_types)
2
+
3
+ Full-featured type system for any ruby project. Support for custom type definitioning,
4
+ type validation, type casting and type categorizing. Provides a set of commonly used type
5
+ categories and general purpose types. Has a flexible and simplest type definition toolchain.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem 'smart_types'
11
+ ```
12
+
13
+ ```shell
14
+ bundle install
15
+ # --- or ---
16
+ gem install smart_types
17
+ ```
18
+
19
+ ```ruby
20
+ require 'smart_core/types'
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Supported types
26
+
27
+ - Primitive Value Types:
28
+
29
+ ```ruby
30
+ SmartCore::Types::Value::Any
31
+ SmartCore::Types::Value::String
32
+ SmartCore::Types::Value::Symbol
33
+ SmartCore::Types::Value::Text
34
+ SmartCore::Types::Value::Integer
35
+ SmartCore::Types::Value::Float
36
+ SmartCore::Types::Value::Numeric
37
+ SmartCore::Types::Value::Boolean
38
+ SmartCore::Types::Value::Array
39
+ SmartCore::Types::Value::Hash
40
+ SmartCore::Types::Value::Proc
41
+ SmartCore::Types::Value::Class
42
+ SmartCore::Types::Value::Module
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Type validation and type casting
48
+
49
+ ```ruby
50
+ # documentation is coming
51
+ ```
52
+
53
+ ---
54
+
55
+ ## Custom type definition
56
+
57
+ ```ruby
58
+ # documentation is coming
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Type system integration
64
+
65
+ ```ruby
66
+ # documentation is coming
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Contributing
72
+
73
+ - Fork it ( https://github.com/smart-rb/smart_types )
74
+ - Create your feature branch (`git checkout -b feature/my-new-feature`)
75
+ - Commit your changes (`git commit -am '[feature_context] Add some feature'`)
76
+ - Push to the branch (`git push origin feature/my-new-feature`)
77
+ - Create new Pull Request
78
+
79
+ ## License
80
+
81
+ Released under MIT License.
82
+
83
+ ## Authors
84
+
85
+ [Rustam Ibragimov](https://github.com/0exp)
@@ -0,0 +1,21 @@
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-performance'
15
+ t.requires << 'rubocop-rspec'
16
+ t.requires << 'rubocop-rake'
17
+ end
18
+
19
+ RSpec::Core::RakeTask.new(:rspec)
20
+
21
+ task default: :rspec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'smart_core/types'
6
+
7
+ require 'irb'
8
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'smart_core'
4
+
5
+ # @api public
6
+ # @since 0.1.0
7
+ module SmartCore::Types
8
+ require_relative 'types/version'
9
+ require_relative 'types/errors'
10
+ require_relative 'types/system'
11
+ require_relative 'types/primitive'
12
+ require_relative 'types/value'
13
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore::Types
4
+ # @api public
5
+ # @since 0.1.0
6
+ Error = Class.new(SmartCore::Error)
7
+
8
+ # @api public
9
+ # @since 0.1.0
10
+ ArgumentError = Class.new(SmartCore::ArgumentError)
11
+
12
+ # @api public
13
+ # @since 0.1.0
14
+ NameError = Class.new(SmartCore::NameError)
15
+
16
+ # @api public
17
+ # @since 0.1.0
18
+ TypeCastingError = Class.new(Error)
19
+
20
+ # @api public
21
+ # @since 0.1.0
22
+ NoCheckerDefinitionError = Class.new(Error)
23
+
24
+ # @api public
25
+ # @since 0.1.0
26
+ IncorrectTypeNameError = Class.new(NameError)
27
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.1.0
5
+ class SmartCore::Types::Primitive
6
+ require_relative 'primitive/caster'
7
+ require_relative 'primitive/undefined_caster'
8
+ require_relative 'primitive/checker'
9
+ require_relative 'primitive/sum_checker'
10
+ require_relative 'primitive/mult_checker'
11
+ require_relative 'primitive/factory'
12
+ require_relative 'primitive/sum_factory'
13
+ require_relative 'primitive/mult_factory'
14
+
15
+ # @since 0.1.0
16
+ include SmartCore::Types::System::ProducerDSL
17
+
18
+ # @return [SmartCore::Types::Primitive::Checker]
19
+ #
20
+ # @api private
21
+ # @since 0.1.0
22
+ attr_reader :checker
23
+
24
+ # @return [SmartCore::Types::Primitive::Caster]
25
+ #
26
+ # @api private
27
+ # @since 0.1.0
28
+ attr_reader :caster
29
+
30
+ # @param checker [SmartCore::Types::Primitive::Checker]
31
+ # @param caster [SmartCore::Types::Primitive::Caster]
32
+ # @return [void]
33
+ #
34
+ # @api private
35
+ # @since 0.1.0
36
+ def initialize(checker, caster)
37
+ @checker = checker
38
+ @caster = caster
39
+ end
40
+
41
+ # @param value [Any]
42
+ # @return [Boolean]
43
+ #
44
+ # @api public
45
+ # @since 0.1.0
46
+ def valid?(value)
47
+ checker.call(value)
48
+ end
49
+
50
+ # @param value [Any]
51
+ # @return [Any]
52
+ #
53
+ # @api public
54
+ # @since 0.1.0
55
+ def cast(value)
56
+ caster.call(value)
57
+ end
58
+
59
+ # @param another_primitive [SmartCore::Types::Primitive]
60
+ # @return [SmartCore::Types::Primitive]
61
+ #
62
+ # @api public
63
+ # @since 0.1.0
64
+ def |(another_primitive)
65
+ self.class::SumFactory.create_type(self, another_primitive)
66
+ end
67
+
68
+ # @param another_primitive [SmartCore::Types::Primitive]
69
+ # @return [SmartCore::Types::Primitive]
70
+ #
71
+ # @api public
72
+ # @since 0.1.0
73
+ def &(another_primitive)
74
+ self.class::MultFactory.create_type(self, another_primitive)
75
+ end
76
+ end