-
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
0 parents
commit 27b72b6
Showing
23 changed files
with
719 additions
and
0 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,6 @@ | ||
.bundle/ | ||
.idea/ | ||
.yardoc/ | ||
doc/ | ||
log/*.log | ||
pkg/ |
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 @@ | ||
--require rails_helper |
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,9 @@ | ||
require: | ||
- rubocop-rails | ||
- rubocop-performance | ||
|
||
AllCops: | ||
DisplayCopNames: true | ||
DisplayStyleGuide: true | ||
NewCops: enable | ||
TargetRubyVersion: 2.7 |
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 @@ | ||
app/**/*.rb lib/**/*.{rb,rake} --list-undoc |
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | ||
|
||
gemspec | ||
|
||
gem 'rubocop-performance', '~> 1.5', require: false | ||
gem 'rubocop-rails', '~> 2.7', require: false |
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,216 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
carbonyte (0.1.0) | ||
interactor-rails (~> 2.0) | ||
jsonapi-serializer (~> 2.0) | ||
pundit (~> 2.1) | ||
rails (~> 6.0.3, >= 6.0.3.2) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
actioncable (6.0.3.2) | ||
actionpack (= 6.0.3.2) | ||
nio4r (~> 2.0) | ||
websocket-driver (>= 0.6.1) | ||
actionmailbox (6.0.3.2) | ||
actionpack (= 6.0.3.2) | ||
activejob (= 6.0.3.2) | ||
activerecord (= 6.0.3.2) | ||
activestorage (= 6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
mail (>= 2.7.1) | ||
actionmailer (6.0.3.2) | ||
actionpack (= 6.0.3.2) | ||
actionview (= 6.0.3.2) | ||
activejob (= 6.0.3.2) | ||
mail (~> 2.5, >= 2.5.4) | ||
rails-dom-testing (~> 2.0) | ||
actionpack (6.0.3.2) | ||
actionview (= 6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
rack (~> 2.0, >= 2.0.8) | ||
rack-test (>= 0.6.3) | ||
rails-dom-testing (~> 2.0) | ||
rails-html-sanitizer (~> 1.0, >= 1.2.0) | ||
actiontext (6.0.3.2) | ||
actionpack (= 6.0.3.2) | ||
activerecord (= 6.0.3.2) | ||
activestorage (= 6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
nokogiri (>= 1.8.5) | ||
actionview (6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
builder (~> 3.1) | ||
erubi (~> 1.4) | ||
rails-dom-testing (~> 2.0) | ||
rails-html-sanitizer (~> 1.1, >= 1.2.0) | ||
activejob (6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
globalid (>= 0.3.6) | ||
activemodel (6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
activerecord (6.0.3.2) | ||
activemodel (= 6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
activestorage (6.0.3.2) | ||
actionpack (= 6.0.3.2) | ||
activejob (= 6.0.3.2) | ||
activerecord (= 6.0.3.2) | ||
marcel (~> 0.3.1) | ||
activesupport (6.0.3.2) | ||
concurrent-ruby (~> 1.0, >= 1.0.2) | ||
i18n (>= 0.7, < 2) | ||
minitest (~> 5.1) | ||
tzinfo (~> 1.1) | ||
zeitwerk (~> 2.2, >= 2.2.2) | ||
ast (2.4.1) | ||
builder (3.2.4) | ||
coderay (1.1.3) | ||
concurrent-ruby (1.1.6) | ||
crass (1.0.6) | ||
diff-lcs (1.3) | ||
erubi (1.9.0) | ||
globalid (0.4.2) | ||
activesupport (>= 4.2.0) | ||
i18n (1.8.2) | ||
concurrent-ruby (~> 1.0) | ||
inch (0.8.0) | ||
pry | ||
sparkr (>= 0.2.0) | ||
term-ansicolor | ||
yard (~> 0.9.12) | ||
interactor (3.1.2) | ||
interactor-rails (2.2.1) | ||
interactor (~> 3.0) | ||
rails (>= 4.2) | ||
jsonapi-serializer (2.0.0) | ||
activesupport (>= 4.2) | ||
loofah (2.6.0) | ||
crass (~> 1.0.2) | ||
nokogiri (>= 1.5.9) | ||
mail (2.7.1) | ||
mini_mime (>= 0.1.1) | ||
marcel (0.3.3) | ||
mimemagic (~> 0.3.2) | ||
method_source (1.0.0) | ||
mimemagic (0.3.5) | ||
mini_mime (1.0.2) | ||
mini_portile2 (2.4.0) | ||
minitest (5.14.0) | ||
nio4r (2.5.2) | ||
nokogiri (1.10.10) | ||
mini_portile2 (~> 2.4.0) | ||
parallel (1.19.2) | ||
parser (2.7.1.4) | ||
ast (~> 2.4.1) | ||
pry (0.13.1) | ||
coderay (~> 1.1) | ||
method_source (~> 1.0) | ||
pundit (2.1.0) | ||
activesupport (>= 3.0.0) | ||
rack (2.2.2) | ||
rack-test (1.1.0) | ||
rack (>= 1.0, < 3) | ||
rails (6.0.3.2) | ||
actioncable (= 6.0.3.2) | ||
actionmailbox (= 6.0.3.2) | ||
actionmailer (= 6.0.3.2) | ||
actionpack (= 6.0.3.2) | ||
actiontext (= 6.0.3.2) | ||
actionview (= 6.0.3.2) | ||
activejob (= 6.0.3.2) | ||
activemodel (= 6.0.3.2) | ||
activerecord (= 6.0.3.2) | ||
activestorage (= 6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
bundler (>= 1.3.0) | ||
railties (= 6.0.3.2) | ||
sprockets-rails (>= 2.0.0) | ||
rails-dom-testing (2.0.3) | ||
activesupport (>= 4.2.0) | ||
nokogiri (>= 1.6) | ||
rails-html-sanitizer (1.3.0) | ||
loofah (~> 2.3) | ||
railties (6.0.3.2) | ||
actionpack (= 6.0.3.2) | ||
activesupport (= 6.0.3.2) | ||
method_source | ||
rake (>= 0.8.7) | ||
thor (>= 0.20.3, < 2.0) | ||
rainbow (3.0.0) | ||
rake (13.0.1) | ||
regexp_parser (1.7.1) | ||
rexml (3.2.4) | ||
rspec-core (3.9.2) | ||
rspec-support (~> 3.9.3) | ||
rspec-expectations (3.9.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-mocks (3.9.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-rails (4.0.0) | ||
actionpack (>= 4.2) | ||
activesupport (>= 4.2) | ||
railties (>= 4.2) | ||
rspec-core (~> 3.9) | ||
rspec-expectations (~> 3.9) | ||
rspec-mocks (~> 3.9) | ||
rspec-support (~> 3.9) | ||
rspec-support (3.9.3) | ||
rubocop (0.88.0) | ||
parallel (~> 1.10) | ||
parser (>= 2.7.1.1) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.7) | ||
rexml | ||
rubocop-ast (>= 0.1.0, < 1.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 1.4.0, < 2.0) | ||
rubocop-ast (0.3.0) | ||
parser (>= 2.7.1.4) | ||
rubocop-performance (1.5.2) | ||
rubocop (>= 0.71.0) | ||
rubocop-rails (2.7.1) | ||
activesupport (>= 4.2.0) | ||
rack (>= 1.1) | ||
rubocop (>= 0.87.0) | ||
ruby-progressbar (1.10.1) | ||
sparkr (0.4.1) | ||
sprockets (4.0.2) | ||
concurrent-ruby (~> 1.0) | ||
rack (> 1, < 3) | ||
sprockets-rails (3.2.1) | ||
actionpack (>= 4.0) | ||
activesupport (>= 4.0) | ||
sprockets (>= 3.0.0) | ||
sync (0.5.0) | ||
term-ansicolor (1.7.1) | ||
tins (~> 1.0) | ||
thor (1.0.1) | ||
thread_safe (0.3.6) | ||
tins (1.25.0) | ||
sync | ||
tzinfo (1.2.7) | ||
thread_safe (~> 0.1) | ||
unicode-display_width (1.7.0) | ||
websocket-driver (0.7.3) | ||
websocket-extensions (>= 0.1.0) | ||
websocket-extensions (0.1.5) | ||
yard (0.9.25) | ||
zeitwerk (2.3.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
carbonyte! | ||
inch (~> 0.8.0) | ||
rspec-rails (~> 4.0) | ||
rubocop-performance (~> 1.5) | ||
rubocop-rails (~> 2.7) | ||
|
||
BUNDLED WITH | ||
2.1.4 |
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,22 @@ | ||
# Carbonyte | ||
Build Microservices-oriented Architectures with ease. | ||
|
||
## Installation | ||
Add this line to your microservice Gemfile: | ||
|
||
```ruby | ||
gem 'carbonyte' | ||
``` | ||
|
||
And then execute: | ||
```bash | ||
$ bundle | ||
``` | ||
|
||
## Usage | ||
TBD | ||
|
||
## Contributing | ||
Before pushing: | ||
* Run `rubocop` to show code styles offences | ||
* Run `inch` to show documentation state |
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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
begin | ||
require 'bundler/setup' | ||
rescue LoadError | ||
puts 'You must `gem install bundler` and `bundle install` to run rake tasks' | ||
end | ||
|
||
require 'rdoc/task' | ||
|
||
RDoc::Task.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'Carbonyte' | ||
rdoc.options << '--line-numbers' | ||
rdoc.rdoc_files.include('README.md') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
load 'rails/tasks/statistics.rake' | ||
|
||
require 'bundler/gem_tasks' |
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Carbonyte | ||
# Carbonyte base class for all controllers | ||
class ApplicationController < ActionController::API | ||
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,61 @@ | ||
# frozen_string_literal: true | ||
|
||
module Carbonyte | ||
# The Rescuable concern rescues controllers from bubbling up the most common exceptions | ||
# and provides a uniformed response body in case of such errors. | ||
# @see https://jsonapi.org/format/#error-objects | ||
module Rescuable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
rescue_from Pundit::NotAuthorizedError, with: :unauthorized | ||
rescue_from Interactor::Failure, with: :interactor_failure | ||
rescue_from ActiveRecord::RecordInvalid, with: :record_invalid | ||
end | ||
|
||
private | ||
|
||
def serialized_errors(payload) | ||
payload = [payload] unless payload.is_a?(Enumerable) | ||
payload.to_json | ||
end | ||
|
||
def unauthorized(exc) | ||
payload = { | ||
code: exc.class.name, | ||
source: { policy: exc.policy.class.name }, | ||
title: 'Not Authorized By Policy', | ||
detail: exc.message | ||
} | ||
render json: serialized_errors(payload), status: :unauthorized | ||
end | ||
|
||
def interactor_failure(exc) | ||
payload = { | ||
code: exc.class.name, | ||
source: { interactor: exc.context._called.last.class.name }, | ||
title: 'Interactor Failure', | ||
detail: exc.context.error | ||
} | ||
render json: serialized_errors(payload), status: :unprocessable_entity | ||
end | ||
|
||
def record_invalid(exc) | ||
payload = errors_for_record(exc.record, exc.class.name).flatten | ||
render json: serialized_errors(payload), status: :unprocessable_entity | ||
end | ||
|
||
def errors_for_record(record, code) | ||
record.messages.map do |field, errors| | ||
errors.map do |error_message| | ||
{ | ||
code: code, | ||
source: { pointer: "attributes/#{field}" }, | ||
title: 'Invalid Field ', | ||
detail: error_message | ||
} | ||
end | ||
end | ||
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Carbonyte | ||
# Carbonyte base class for all interactors | ||
class ApplicationInteractor | ||
include Interactor | ||
end | ||
end |
Oops, something went wrong.