Skip to content

Instantly share code, notes, and snippets.

View lxbrito's full-sized avatar

Leonardo Xavier de Brito lxbrito

View GitHub Profile
@lxbrito
lxbrito / your_active_business_implementation.rb
Last active March 18, 2019 01:53
ActiveBusiness Service implementation example
# frozen_string_literal: true
# :nodoc:
class YourActiveBusinessImplementation < ActiveBusiness
attr_reader :arg
def self.call(arg)
new(arg).call
end
@lxbrito
lxbrito / active_business_controller.rb
Created March 18, 2019 01:45
ActiveBusinessController - Usage of ActiveBusiness on Controller
# frozen_string_literal: true
# :nodoc:
class ActiveBussinessController < AplicationController
def some_action
# Dealing with params is a controller's responsibility
arg = collect_and_validate_your_params
YourActiveBusinessImplementation.call(arg) do |resp|
resp.success { |payload| render json: payload.to_json, status: 2xx }
@lxbrito
lxbrito / active_business.rb
Created March 18, 2019 01:40
ActiveBusiness - Proposal to ease the pain when refactoring legacy code on fat controllers
# frozen_string_literal: true
# :nodoc:
class ActiveBusiness
attr_reader :resolver
def initialize
@resolver = ActiveBusiness::Resolver.new
yield resolver
end