Skip to content

Instantly share code, notes, and snippets.

@guiltry
Created April 17, 2015 10:21
Show Gist options
  • Save guiltry/0af3af5be2d30414ba78 to your computer and use it in GitHub Desktop.
Save guiltry/0af3af5be2d30414ba78 to your computer and use it in GitHub Desktop.
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
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