Skip to content

Instantly share code, notes, and snippets.

@iain
Created January 28, 2012 12:24
Show Gist options
  • Save iain/1694142 to your computer and use it in GitHub Desktop.
Save iain/1694142 to your computer and use it in GitHub Desktop.
class Users::Register
def self.call(attributes)
new(attributes).call
end
def initialize(attributes)
@attributes = attributes
end
def call
if valid?
save_user
create_empty_profile
notify_admins
end
end
private
def valid?
user.valid?
end
def user
@user ||= User.new(@attributes)
end
# etc...
end
# Later on, in the controller for instance:
Users::Register.(params[:user])
@randito
Copy link

randito commented Jun 29, 2012

Cool technique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment