Skip to content

Instantly share code, notes, and snippets.

@ryenski
Created June 27, 2017 18:38
Show Gist options
  • Save ryenski/4696ceb81461e9e4557259c3de2d5fc8 to your computer and use it in GitHub Desktop.
Save ryenski/4696ceb81461e9e4557259c3de2d5fc8 to your computer and use it in GitHub Desktop.
Processing service objects
class MessageCreator
# ...
def call
process!
return result
end
private
def process!
if message.save
deliver_messages
else
(@errors ||= []) << message.errors
end
end
def deliver_messages
# ...
end
def result
OpenStruct.new(success?: !errors, errors: errors.try(:flatten), message: message)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment