Last active
February 4, 2018 08:19
-
-
Save HaiTo/90037fbf2a7333b47bf164b0ba4dd1d2 to your computer and use it in GitHub Desktop.
何とも言えない設計
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
class FollowCommand | |
def initialize(user, params) | |
@user = user | |
@params = params | |
end | |
using UserCommand::Follow | |
def execute! | |
user = User.find(@params[:id]) | |
User.transaction do | |
@user.follow!(user) | |
end | |
end | |
end |
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
class FolloweesController < ApplicationController | |
using UserRepository::Follow | |
def create | |
following_user = User.find(params[:id]) | |
current_user.follow!(following_user) | |
# using UserRepository::Follow { | |
# current_user.follow!(following_user) | |
# } | |
end | |
end |
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
module UserRepository | |
module Follow | |
refine User do | |
def follow!(another_user) | |
relationship.create!(user: self, following: another_user) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment