You are here: Browse Railsplugins Simple Services
Creates a simple services layer with automatic transactional demarcation. To use, simply create a folder at app/services, and add classes that derive from Service::Base. That’s it. All the methods in the service will be wrapped in a transaction by default. Any exception within that method will rollback the transaction.
Services are singletons to reduce memory overhead. And since they’re singletons, they MUST remain stateless.
SimpleServices relies on Aquarium for method aspecting.
sudo gem install aquarium
def transfer(base_acct, target_acct, amt)
base_acct.balance -= amt
base_acct.save!
target_acct.balance += amt
target_acct.save!
end
end
class AccountController < ApplicationController
def update
base = Account.find(params[:base_id])
target = Account.find(params[:target_id])
# use service. enjoy transactions. lather. rinse. repeat.
account_service.transfer(base, target, params[:amount])
end
end
Copyright© 2008 Relevance, Inc., released under the MIT license
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly