g2_command 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 77dad168ef55ca1a4265b1dabf2834eed591ec975ea1dec3bc8d2d33bbc03a8c
4
+ data.tar.gz: c67ef31b7ca990bffa8980def958c910357be7b0e4c8642bb1654123c429dbe6
5
+ SHA512:
6
+ metadata.gz: 9308bedbfa3b49ee7fb73099735dfc9b66c5dfbdf4e3faadd6a6aa0ef256f7adc986718dea96974aefc15cdf6a0ce6b0a6632dfd304637d0bcb451e55a4176bc
7
+ data.tar.gz: 6ba4102ec3a28e0ce6ca769b4be804ee4cf77137dc51770c14fc95befebb017b804d68987de47c1ffc4ccc3e7a815d57ea78702172373329617e11edb2071f98
@@ -0,0 +1,26 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.6
16
+ - name: Configure Bundler
17
+ run: |
18
+ gem install bundler:2.1.4 --no-document
19
+ bundle install --jobs 4 --retry 3
20
+ - name: Run tests with RSpec
21
+ uses: paambaati/codeclimate-action@v2.5.4
22
+ env:
23
+ CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
24
+ with:
25
+ coverageCommand: bundle exec rspec
26
+ debug: false
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,46 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+
7
+ Layout/LineLength:
8
+ Max: 120
9
+
10
+ Layout/MultilineMethodCallIndentation:
11
+ EnforcedStyle: indented_relative_to_receiver
12
+
13
+ Layout/SpaceAroundMethodCallOperator:
14
+ Enabled: true
15
+
16
+ Lint/RaiseException:
17
+ Enabled: true
18
+
19
+ Lint/StructNewOverride:
20
+ Enabled: true
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/ExponentialNotation:
26
+ Enabled: true
27
+
28
+ Style/HashEachMethods:
29
+ Enabled: true
30
+
31
+ Style/HashTransformKeys:
32
+ Enabled: false
33
+
34
+ Style/HashTransformValues:
35
+ Enabled: false
36
+
37
+ Style/PercentLiteralDelimiters:
38
+ PreferredDelimiters:
39
+ default: ()
40
+ '%w': '()'
41
+ '%W': '()'
42
+ '%i': '()'
43
+ '%I': '()'
44
+
45
+ Style/NumericLiterals:
46
+ Enabled: false
@@ -0,0 +1 @@
1
+ ruby 2.6.6
@@ -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 hasghari@g2.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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake', '~> 12.0'
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'rubocop'
10
+ gem 'rubocop-rspec'
11
+ gem 'simplecov', '0.16.1'
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ g2_command (0.1.0)
5
+ activemodel (>= 6.0, < 7)
6
+ activesupport (>= 6.0, < 7)
7
+ dry-initializer (~> 3.0)
8
+ dry-monads (~> 1.3)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (6.0.2.2)
14
+ activesupport (= 6.0.2.2)
15
+ activesupport (6.0.2.2)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.2)
21
+ ast (2.4.0)
22
+ concurrent-ruby (1.1.6)
23
+ diff-lcs (1.3)
24
+ docile (1.3.2)
25
+ dry-core (0.4.9)
26
+ concurrent-ruby (~> 1.0)
27
+ dry-equalizer (0.3.0)
28
+ dry-initializer (3.0.3)
29
+ dry-monads (1.3.5)
30
+ concurrent-ruby (~> 1.0)
31
+ dry-core (~> 0.4, >= 0.4.4)
32
+ dry-equalizer
33
+ i18n (1.8.2)
34
+ concurrent-ruby (~> 1.0)
35
+ jaro_winkler (1.5.4)
36
+ json (2.3.0)
37
+ minitest (5.14.0)
38
+ parallel (1.19.1)
39
+ parser (2.7.1.1)
40
+ ast (~> 2.4.0)
41
+ rainbow (3.0.0)
42
+ rake (12.3.3)
43
+ rexml (3.2.4)
44
+ rspec (3.9.0)
45
+ rspec-core (~> 3.9.0)
46
+ rspec-expectations (~> 3.9.0)
47
+ rspec-mocks (~> 3.9.0)
48
+ rspec-core (3.9.1)
49
+ rspec-support (~> 3.9.1)
50
+ rspec-expectations (3.9.1)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.9.0)
53
+ rspec-mocks (3.9.1)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.9.0)
56
+ rspec-support (3.9.2)
57
+ rubocop (0.82.0)
58
+ jaro_winkler (~> 1.5.1)
59
+ parallel (~> 1.10)
60
+ parser (>= 2.7.0.1)
61
+ rainbow (>= 2.2.2, < 4.0)
62
+ rexml
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (>= 1.4.0, < 2.0)
65
+ rubocop-rspec (1.38.1)
66
+ rubocop (>= 0.68.1)
67
+ ruby-progressbar (1.10.1)
68
+ simplecov (0.16.1)
69
+ docile (~> 1.1)
70
+ json (>= 1.8, < 3)
71
+ simplecov-html (~> 0.10.0)
72
+ simplecov-html (0.10.2)
73
+ thread_safe (0.3.6)
74
+ tzinfo (1.2.7)
75
+ thread_safe (~> 0.1)
76
+ unicode-display_width (1.7.0)
77
+ zeitwerk (2.3.0)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ g2_command!
84
+ rake (~> 12.0)
85
+ rspec (~> 3.0)
86
+ rubocop
87
+ rubocop-rspec
88
+ simplecov (= 0.16.1)
89
+
90
+ BUNDLED WITH
91
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Hamed Asghari
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,41 @@
1
+ # Command
2
+
3
+ This gem is an implementation of the command pattern, heavily inspired and mirroring the implementation by [active_interaction](https://github.com/AaronLasseigne/active_interaction) with the major difference being using the [dry-rb](https://dry-rb.org/) libraries.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'g2_command'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install g2_command
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/g2crowd/g2_command. 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/[USERNAME]/g2_command/blob/master/CODE_OF_CONDUCT.md).
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Command project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/g2crowd/g2_command/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
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
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'command'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/command/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'g2_command'
7
+ spec.version = Command::VERSION
8
+ spec.authors = ['Hamed Asghari']
9
+ spec.email = ['hasghari@g2.com']
10
+
11
+ spec.summary = 'An implementation of the command pattern using dry-rb'
12
+ spec.homepage = 'https://github.com/g2crowd/g2_command'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/g2crowd/g2_command'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'activemodel', '>= 6.0', '< 7'
29
+ spec.add_dependency 'activesupport', '>= 6.0', '< 7'
30
+ spec.add_dependency 'dry-initializer', '~> 3.0'
31
+ spec.add_dependency 'dry-monads', '~> 1.3'
32
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model'
4
+ require 'dry-initializer'
5
+ require 'dry-monads'
6
+
7
+ require 'command/interrupt'
8
+
9
+ module Command
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ extend Dry::Initializer
14
+ include Dry::Monads[:result]
15
+ include ActiveModel::Validations
16
+
17
+ def execute
18
+ raise NotImplementedError
19
+ end
20
+
21
+ def run
22
+ result = if valid?
23
+ begin
24
+ execute
25
+ rescue Command::Interrupt => e
26
+ errors.merge! e.errors
27
+ end
28
+ end
29
+
30
+ errors.empty? ? Success(result) : Failure(errors)
31
+ end
32
+
33
+ def compose(command, *args)
34
+ outcome = command.run(*args)
35
+
36
+ raise Command::Interrupt, outcome.failure if outcome.failure?
37
+
38
+ outcome.value!
39
+ end
40
+
41
+ def inputs
42
+ self.class.dry_initializer.attributes(self)
43
+ end
44
+ end
45
+
46
+ class_methods do
47
+ def run(*args)
48
+ new(*args).run
49
+ end
50
+
51
+ def run!(*args)
52
+ run(*args).value!
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Command
4
+ class Interrupt < StandardError
5
+ attr_reader :errors
6
+
7
+ def initialize(errors)
8
+ super()
9
+
10
+ @errors = errors
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Command
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'command'
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: g2_command
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hamed Asghari
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '6.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '6.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '7'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '6.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '7'
53
+ - !ruby/object:Gem::Dependency
54
+ name: dry-initializer
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: dry-monads
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.3'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.3'
81
+ description:
82
+ email:
83
+ - hasghari@g2.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - ".github/workflows/ruby.yml"
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".rubocop.yml"
92
+ - ".tool-versions"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - g2_command.gemspec
102
+ - lib/command.rb
103
+ - lib/command/interrupt.rb
104
+ - lib/command/version.rb
105
+ - lib/g2_command.rb
106
+ homepage: https://github.com/g2crowd/g2_command
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ homepage_uri: https://github.com/g2crowd/g2_command
111
+ source_code_uri: https://github.com/g2crowd/g2_command
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.3.0
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.0.3
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: An implementation of the command pattern using dry-rb
131
+ test_files: []