Skip to content

Instantly share code, notes, and snippets.

@laser
Created April 14, 2014 17:31
Show Gist options
  • Select an option

  • Save laser/10667799 to your computer and use it in GitHub Desktop.

Select an option

Save laser/10667799 to your computer and use it in GitHub Desktop.
04: UserService implementation
# services/user_service/implementation.rb
class UserService
USER_ATTRIBUTES = %w(id full_name email phone_number)
def initialize(mail_service)
@mail_service = mail_service
end
def get_all_users()
User.all.map &method(:to_serializable)
end
def create_user(user_properties)
user = to_serializable(User.create!(user_properties))
@mail_service.send_email '[email protected]', user['email'], 'subj', 'body'
user
end
private
# make sure we don't try to respond with something that
# doesn't conform to the IDL (like timestamps and such)
def to_serializable(user_model)
user_model.serializable_hash.slice *USER_ATTRIBUTES
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment