Skip to content

Instantly share code, notes, and snippets.

@mattheworiordan
Created November 8, 2013 17:40
Show Gist options
  • Save mattheworiordan/7374708 to your computer and use it in GitHub Desktop.
Save mattheworiordan/7374708 to your computer and use it in GitHub Desktop.
Econsultancy service objects following our discussion
AccountService.sign_up
AccountService.sign_up_for_existing_membership
AccountService.leave_membership
AccountService.move_to_new_membership
sign_up = AccountService.sign_up
if sign_up.success
...
else
errors = sign_up.errors
end
result = AccountService::SignUp.new(attributes)
if result.success
...
else
errors = result.errors
end
class AccountService
def self.sign_up(attribute)
SignUp.new(attribute).call
end
def self.sign_up_for_existing_membership
SignUp.new(attribute, membership).call
end
end
module AccountService
class SignUp
attr_reader :success, :state_variables, :account, :membership
def initialize(attributes)
... set properties
end
def call
# failed
success = false
self
end
private
# whatever
end
end
class ServiceResult
attr_reder :success, :reason, :service_object
def initialize(result, reason, service_object)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment