Service Layer Pattern Implementation.
Provide an easy way to write service layer object.
Services are used to encapsulate application logic business.
Add this line to your application's Gemfile:
gem 'service_layer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install service_layer
class MatchingService < ApplicationService
property :tender
render :matches_created
def perform
# business logic
end
end
class TendersController < ApplicationController
def update
@tender = Tender.find(params[:id])
result = MatchingService.perform(tender: @tender)
respond_to do |format|
if result.success?
format.html { redirect_to tender_path(@tender), status: :see_other }
else
format.html do
flash.now[:message] = t(result.error.message)
render :edit
end
end
end
end
end
May be set to one of [:dry, :without]
. :without
is the default one but also
deprecated. Override with :dry
.
# config/initializers/service_layer.rb
ServiceLayer.configure do |config|
config.monad = :dry
end
Bug reports and pull requests are welcome on GitHub.
Everyone interacting in the ServiceLayer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
The gem is available as open source under the terms of the MIT License.