Skip to content

dodgerogers/nucleus-rails

Repository files navigation

Nucleus Rails

Gem Version Circle Code Climate

nucleus-rails adapts nucleus-core to work with the rails framework.

Quick start

  1. Install the gem

Gemfile

gem 'nucleus-rails'
  1. Initialize nucleus-rails

config/initializers/nucleus-rails.rb

require "nucleus-rails"

NucleusCore.configure do |config|
  config.logger = Rails.logger
  config.default_response_format = :json
  config.exceptions = {
    not_found: ActiveRecord::RecordNotFound,
    unprocessible: [ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved],
    bad_request: Apipie::ParamError,
    unauthorized: Pundit::NotAuthorizedError
  }
end
  1. Include the responder module in your controller, call your business logic inside execute block, then return either a NucleusView, a Nucleus::Operation::Context, or raise an exception to render a response.
class PaymentsController < ApplicationController
  include NucleusRails::Responder

  def create
    execute do |req|
      context, _process = MyWorkflow.call(id: req.parameters[:id])

      return context unless context.success?

      return MyView.new(resource: context.resource)
    end
  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!

About

An Nucleus-Core adapter for Rails

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published