Created
November 21, 2012 00:54
-
-
Save CoryFoy/4122352 to your computer and use it in GitHub Desktop.
This file contains 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
#non SRP | |
def map | |
user = User.find(params[:id]) | |
user.name = params[:name] | |
user.email = params[:email] | |
end | |
#SRP | |
#spec | |
def save | |
find_user | |
map_params_to_user_fields | |
update_user | |
end | |
#impl | |
def find_user | |
@user = User.find(params[:id]) | |
end | |
def map_params_to_user_fields | |
@user_vals = {} | |
@user_vals[:name] = params[:name] | |
@user_vals[:email] = params[:email] | |
end | |
def update_user | |
@user.update!(@user_vals) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment