shiyo 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01a8618ea358901acad9f198594959ce443730b01447cf5e47ceca99aaa695cf
4
+ data.tar.gz: 3e6685943a96003656e015de60ca82bcd38b055380bf20fabf5bfc81953cff62
5
+ SHA512:
6
+ metadata.gz: 9a1483a64c112872659b413ba762ad9b3f8d68a74ee390820d2c1a566d54479d47aa05e4ccc6ab73908fe163b51f91e00add1443fe859889041bdd75ea6fc525
7
+ data.tar.gz: 80c7ea2aa246bb9482c961cf10cbcfa957e4b86c088f3f34668e8315a42aad23b65fe4322077229cba271c8a1b05adb9512c8d35b371bd89e970083b83952dd5
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - 'Rakefile'
18
+ - '**/*.rake'
19
+ - 'spec/**/*.rb'
20
+ - '**/*.gemspec'
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-03-12
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
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 j.e.miyake@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.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in shiyo.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "rubocop-rspec", "~> 2.9"
15
+
16
+ gem "yard", "~> 0.9"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Takuma Miyake
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.
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # Shiyo
2
+ [![johnny-miyake](https://circleci.com/gh/johnny-miyake/shiyo.svg?style=svg)](https://github.com/johnny-miyake/shiyo)
3
+
4
+ Shiyo is a minimal framework that supports writing your business rules using the Specification pattern.
5
+ It enables to build composite specifications by method chaining like;
6
+ ```ruby
7
+ spec1.and(spec2.or(spec3)).satisfied_by?(candidate)
8
+ ```
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem "shiyo"
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install shiyo
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ # A specification class
30
+ class ContainerFeatureSpec
31
+ include Shiyo::Specification
32
+
33
+ TYPE = { armored: "armored", ventilated: "ventilated" }.freeze
34
+
35
+ def initialize container_feature
36
+ @container_feature = TYPE.fetch(container_feature)
37
+ end
38
+
39
+ def satisfied_by? container
40
+ container.feature.to_s == @container_feature
41
+ end
42
+ end
43
+
44
+ # Another specification class
45
+ class ContainerUsedSpec
46
+ include Shiyo::Specification
47
+
48
+ def initialize used:
49
+ @used = used
50
+ end
51
+
52
+ def satisfied_by? container
53
+ container.used? == @used
54
+ end
55
+ end
56
+
57
+ # The class of the candidate object
58
+ class Container
59
+ attr_reader :feature
60
+
61
+ def initialize feature, used: false
62
+ @feature = feature
63
+ @used = !!used
64
+ end
65
+
66
+ def used?
67
+ @used
68
+ end
69
+ end
70
+
71
+ # containers
72
+ brand_new_armored_container = Container.new(:armored, used: false)
73
+ used_ventilated_container = Container.new(:ventilated, used: true)
74
+ used_cheep_container = Container.new(:cheep, used: true)
75
+
76
+ # simple specifications
77
+ armored_spec = ContainerFeatureSpec.new(:armored)
78
+ ventilated_spec = ContainerFeatureSpec.new(:ventilated)
79
+ used_spec = ContainerUsedSpec.new(used: true)
80
+ brand_new_spec = ContainerUsedSpec.new(used: false)
81
+
82
+ armored_spec.satisfied_by?(brand_new_armored_container)
83
+ #=> true
84
+ armored_spec.satisfied_by?(used_ventilated_container)
85
+ #=> false
86
+ used_spec.satisfied_by?(used_ventilated_container)
87
+ #=> true
88
+
89
+ # composite specifications
90
+ used_ventilated_spec = ventilated_spec.and(used_spec)
91
+ brand_new_ventilated_spec = ventilated_spec.and(brand_new_spec)
92
+ cheep_spec = Shiyo::Not(armored_spec.or(ventilated_spec))
93
+
94
+ used_ventilated_spec.satisfied_by?(used_ventilated_container)
95
+ #=> true
96
+ brand_new_ventilated_spec.satisfied_by?(used_ventilated_container)
97
+ #=> false
98
+ cheep_spec.satisfied_by?(used_cheep_container)
99
+ #=> true
100
+ armored_spec.satisfied_by?(used_cheep_container)
101
+ #=> false
102
+ ```
103
+
104
+ ## Development
105
+
106
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
107
+
108
+ 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).
109
+
110
+ ## Contributing
111
+
112
+ Bug reports and pull requests are welcome on GitHub at https://github.com/johnny-miyake/shiyo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/johnny-miyake/shiyo/blob/master/CODE_OF_CONDUCT.md).
113
+
114
+ ## License
115
+
116
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
117
+
118
+ ## Code of Conduct
119
+
120
+ Everyone interacting in the Shiyo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/johnny-miyake/shiyo/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/lib/shiyo/and.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shiyo
4
+ # The class to create a composite specification for checking
5
+ # whether the candidate satisfies both of the two specifications.
6
+ class And
7
+ include Shiyo::Specification
8
+ # A new instance of Shiyo::And
9
+ #
10
+ # @param one [Shiyo::Specification] A specification object.
11
+ # @param other [Shiyo::Specification] The other specification object.
12
+ def initialize(one, other)
13
+ super()
14
+ @one = Shiyo::Specification(one)
15
+ @other = Shiyo::Specification(other)
16
+ end
17
+
18
+ # Inspects whether the candidate satisfies the both of the wrapped specifications.
19
+ #
20
+ # @param candidate [Object] The candidate object to be inspected.
21
+ # @return [Boolean] The result.
22
+ def satisfied_by?(candidate)
23
+ @one.satisfied_by?(candidate) && @other.satisfied_by?(candidate)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shiyo
4
+ # The module to provide conversion methods.
5
+ module Conversion
6
+ # rubocop:disable Naming/MethodName
7
+
8
+ # Ensures the object to be a Shiyo compatible object.
9
+ # @param object Any object.
10
+ # @raise [Shiyo::ConversionError]
11
+ def Specification(object)
12
+ check_compatibility_of(object)
13
+ end
14
+ # rubocop:enable Naming/MethodName
15
+
16
+ module_function
17
+
18
+ # A private method used by `#Specification()`.
19
+ # @!visibility private
20
+ def check_compatibility_of(object)
21
+ object.to_shiyo
22
+ rescue NoMethodError => e
23
+ raise Shiyo::Error::IncompatibleObject, <<~MESSAGE
24
+ #{e.message}
25
+ Can't convert #{object} into Shiyo compatible object.
26
+ The class of the object must include `Shiyo::Specification`,
27
+ or have `#to_shiyo()` for compatibility.
28
+ MESSAGE
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shiyo
4
+ module Error
5
+ class ShiyoError < StandardError; end
6
+
7
+ class IncompatibleObject < ShiyoError; end
8
+ end
9
+ end
data/lib/shiyo/not.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shiyo
4
+ # The class to create a wrapper specification for checking
5
+ # whether the candidate does not satisfy the wrapped specification.
6
+ class Not
7
+ include Shiyo::Specification
8
+ # A new instance of Shiyo::Not
9
+ #
10
+ # @param wrapped [Shiyo::Specification] A specification object.
11
+ def initialize(wrapped)
12
+ super()
13
+ @wrapped = Shiyo::Specification(wrapped)
14
+ end
15
+
16
+ # Inspects whether the candidate does not satisfy the wrapped specification.
17
+ #
18
+ # @param candidate [Object] The candidate object to be inspected.
19
+ # @return [Boolean] The result.
20
+ def satisfied_by?(candidate)
21
+ !@wrapped.satisfied_by?(candidate)
22
+ end
23
+ end
24
+ end
data/lib/shiyo/or.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shiyo
4
+ # The class to create a composite specification for checking
5
+ # whether the candidate satisfies any of the two specifications.
6
+ class Or
7
+ include Shiyo::Specification
8
+ # A new instance of Shiyo::Or
9
+ #
10
+ # @param one [Shiyo::Specification] A specification object.
11
+ # @param other [Shiyo::Specification] The other specification object.
12
+ def initialize(one, other)
13
+ super()
14
+ @one = Shiyo::Specification(one)
15
+ @other = Shiyo::Specification(other)
16
+ end
17
+
18
+ # Inspects whether the candidate satisfies any of the wrapped specifications.
19
+ #
20
+ # @param candidate [Object] The candidate object to be inspected.
21
+ # @return [Boolean] The result.
22
+ def satisfied_by?(candidate)
23
+ @one.satisfied_by?(candidate) || @other.satisfied_by?(candidate)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shiyo
4
+ # The mixin module that provides basic methods to implement user specifications.
5
+ module Specification
6
+ # Composes a Spec::And specification of self and the other specification.
7
+ #
8
+ # @param other [Shiyo::Specification] A specification object to combine with self.
9
+ # @return [Shiyo::And] The composed specification.
10
+ def and(other)
11
+ Shiyo::And.new(self, other)
12
+ end
13
+
14
+ # Composes a Spec::Or specification of self and the other specification.
15
+ #
16
+ # @param other [Shiyo::Specification] A specification object to combine with self.
17
+ # @return [Shiyo::Or] The composed specification.
18
+ def or(other)
19
+ Shiyo::Or.new(self, other)
20
+ end
21
+
22
+ # Inspects whether the candidate satisfies the the specification.
23
+ # This method must be overridden by the class that includes this module.
24
+ #
25
+ # @param candidate [Object] The candidate object to be inspected.
26
+ # @return [void]
27
+ # @raise [NotImplementedError]
28
+ def satisfied_by?(_candidate)
29
+ raise NotImplementedError, "Implement your inspection code."
30
+ end
31
+
32
+ def to_shiyo
33
+ self
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shiyo
4
+ # The module to provide syntax suggers.
5
+ module SyntaxSugger
6
+ # rubocop:disable Naming/MethodName
7
+
8
+ # The syntax sugger for `Shiyo::Not.new`
9
+ # @param object Any object.
10
+ # @return [Shiyo::Not]
11
+ def Not(object)
12
+ Shiyo::Not.new(object)
13
+ end
14
+ # rubocop:enable Naming/MethodName
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shiyo
4
+ VERSION = "0.1.0"
5
+ end
data/lib/shiyo.rb ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "shiyo/error"
4
+ require_relative "shiyo/version"
5
+ require_relative "shiyo/conversion"
6
+ require_relative "shiyo/syntax_sugger"
7
+ require_relative "shiyo/specification"
8
+ require_relative "shiyo/and"
9
+ require_relative "shiyo/or"
10
+ require_relative "shiyo/not"
11
+
12
+ # The top module of Shiyo
13
+ module Shiyo
14
+ extend Shiyo::Conversion
15
+ extend Shiyo::SyntaxSugger
16
+ end
data/sig/shiyo.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Shiyo
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shiyo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takuma Miyake
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: " Shiyo is a minimal framework that supports writing your business
14
+ rules using the Specification pattern.\n"
15
+ email:
16
+ - j.e.miyake@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - lib/shiyo.rb
30
+ - lib/shiyo/and.rb
31
+ - lib/shiyo/conversion.rb
32
+ - lib/shiyo/error.rb
33
+ - lib/shiyo/not.rb
34
+ - lib/shiyo/or.rb
35
+ - lib/shiyo/specification.rb
36
+ - lib/shiyo/syntax_sugger.rb
37
+ - lib/shiyo/version.rb
38
+ - sig/shiyo.rbs
39
+ homepage: https://github.com/johnny-miyake/shiyo
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://github.com/johnny-miyake/shiyo
44
+ source_code_uri: https://github.com/johnny-miyake/shiyo
45
+ changelog_uri: https://github.com/johnny-miyake/shiyo/blob/master/CHANGELOG.md
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.1.6
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A minimal framework for the Specification pattern.
65
+ test_files: []