Nucleus Rails
- Quick start
- Support
- License
- Code of conduct
- Contribution guide
nucleus-rails
adapts nucleus-core
to work with the rails framework.
Quick start
- Install the gem
Gemfile
gem 'nucleus-rails'
- Initialize
nucleus-rails
config/initializers/nucleus-rails.rb
require "nucleus-rails"
NucleusCore.configure do |config|
config.exceptions = {
not_found: ActiveRecord::RecordNotFound,
unprocessible: [ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved],
bad_request: Apipie::ParamError,
unauthorized: Pundit::NotAuthorizedError
}
end
- Include the
responder
module in your controller, call your business logic insideexecute
block, then return either aNucleusView
, aNucleus::Operation::Context
, or raise an exception to render a response.
class PaymentsController < ApplicationController
include NucleusRails::Responder
def create
render_response do |req|
context, _process = MyWorkflow.call(id: req.parameters[:id])
return context unless context.success?
return MyView.new(resource: context.resource)
end
end
def show
context = MyOperation.call(id: params[:id])
return render_entity(context) unless context.success?
return render_entity(MyView.new(resource: context.resource))
end
end
Support
If you want to report a bug, or have ideas, feedback or questions about the gem, let me know via GitHub issues and I will do my best to provide a helpful answer. Happy hacking!
License
The gem is available as open source under the terms of the MIT License.
Code of conduct
Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
Contribution guide
Pull requests are welcome!