Created
April 14, 2014 17:31
-
-
Save laser/10667799 to your computer and use it in GitHub Desktop.
04: UserService implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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