-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
291edf5
commit 4ca7018
Showing
20 changed files
with
184 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Rubocop | ||
on: [pull_request] | ||
|
||
jobs: | ||
linters: | ||
name: Linters | ||
runs-on: ubuntu-latest | ||
if: ${{ github.actor != 'dependabot[bot]' }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Ruby | ||
uses: ruby/setup-ruby@v1 | ||
- name: Setup Rubocop | ||
# A bug requires the use of `bundle install` to use `rubocop-rails`. A fix is coming to Rubocop. | ||
# See: https://github.com/rubocop/rubocop/issues/12823 | ||
run: | | ||
bundle install | ||
- name: Run Rubocop | ||
# We must pass the list of files because for now, rubocop on the entire project throws too many errors. | ||
# We exclude the db/schema.rb file explicitly because passing a list of files will override the `AllCops.Exclude` config in .rubocop.yml | ||
run: | | ||
FILES=$(git diff --diff-filter=d --name-only origin/${{ github.base_ref }}...HEAD -- '*.rb' ':!db/*schema.rb') | ||
if [ -z "$FILES" ]; then | ||
echo "No Ruby files to lint" | ||
exit 0 | ||
else | ||
echo "Linting Ruby files" | ||
bundle exec rubocop $FILES | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "turbine/version" | ||
|
||
# Base structure | ||
require "turbine/service/result" | ||
require "turbine/service/base" | ||
|
||
# Failures | ||
require "turbine/failures/base_failure" | ||
require "turbine/failures/forbidden_failure" | ||
require "turbine/failures/not_allowed_failure" | ||
require "turbine/failures/not_found_failure" | ||
require "turbine/failures/service_failure" | ||
require "turbine/failures/unauthorized_failure" | ||
require "turbine/failures/validation_failure" |
2 changes: 1 addition & 1 deletion
2
lib/turbine_service/failures/base_failure.rb → lib/turbine/failures/base_failure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ine_service/failures/forbidden_failure.rb → lib/turbine/failures/forbidden_failure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...e_service/failures/not_allowed_failure.rb → lib/turbine/failures/not_allowed_failure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ine_service/failures/not_found_failure.rb → lib/turbine/failures/not_found_failure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rbine_service/failures/service_failure.rb → lib/turbine/failures/service_failure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
..._service/failures/unauthorized_failure.rb → lib/turbine/failures/unauthorized_failure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Turbine | ||
module Service | ||
class Base | ||
Result = Turbine::Service::Result | ||
|
||
def self.call(*args, **keyword_args, &block) | ||
new(*args, **keyword_args).call(&block) | ||
end | ||
|
||
def initialize(*, **) | ||
@result = self.class::Result.new | ||
end | ||
|
||
def call(**args, &block) | ||
raise NotImplementedError | ||
end | ||
|
||
private | ||
|
||
attr_reader :result | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
module Turbine | ||
module Service | ||
class Result | ||
attr_reader :error | ||
|
||
def initialize | ||
@failure = false | ||
@error = nil | ||
end | ||
|
||
def failure? | ||
failure | ||
end | ||
|
||
def success? | ||
!failure | ||
end | ||
|
||
def fail_with_error!(error) | ||
@failure = true | ||
@error = error | ||
|
||
self | ||
end | ||
|
||
def forbidden_failure!(code: "feature_unavailable") | ||
fail_with_error!(Turbine::Failures::ForbiddenFailure.new(self, code)) | ||
end | ||
|
||
def not_allowed_failure!(code:) | ||
fail_with_error!(Turbine::Failures::NotAllowedFailure.new(self, code)) | ||
end | ||
|
||
def not_found_failure!(resource:) | ||
fail_with_error!(Turbine::Failures::NotFoundFailure.new(self, resource)) | ||
end | ||
|
||
def service_failure!(code:, message:) | ||
fail_with_error!(Turbine::Failures::ServiceFailure.new(self, code, message)) | ||
end | ||
|
||
def unauthorized_failure!(code: "unauthorized") | ||
fail_with_error!(Turbine::Failures::UnauthorizedFailure.new(self, code)) | ||
end | ||
|
||
def validation_failure!(errors:) | ||
fail_with_error!(Turbine::Failures::ValidationFailure.new(self, errors)) | ||
end | ||
|
||
def record_validation_failure!(record) | ||
validation_failure!(errors: record.errors.messages) | ||
end | ||
|
||
def single_validation_failure!(code:, field: :base) | ||
validation_failure!(errors: {field.to_sym => [code]}) | ||
end | ||
|
||
def raise_if_error! | ||
return self if success? | ||
|
||
raise(error) | ||
end | ||
|
||
private | ||
|
||
attr_accessor :failure | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module TurbineService | ||
module Turbine | ||
VERSION = "0.0.1" | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.