Created
April 17, 2015 10:21
-
-
Save guiltry/0af3af5be2d30414ba78 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
class Factory::User | |
def self.make_user(_user_params) | |
if user_params[:type] == "Knight" | |
@user = Knight.new(_user_params) | |
@user.increase_strength(10) | |
@user.decrease_agility(4) | |
# You can add specific logic that come from "unexpected feature" here. | |
# Without editing all logic-contained files. | |
elsif user_params[:type] == "Archer" | |
@user = Archer.new(_user_params) | |
@user.decrease_strength(6) | |
@user.increase_agility(8) | |
end | |
# ... | |
return @user | |
end | |
end |
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
class User < ActiveRecord::Base | |
end | |
class Knight < User | |
end | |
class Archer < User | |
end | |
class UserController < ApplicationController | |
def create | |
@user = Factory::User.make_user(user_params) | |
# ... | |
end | |
end | |
class Admin::UserController < ApplicationController | |
def create | |
@user = Factory::User.make_user(user_params) | |
# ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment