Skip to content

Instantly share code, notes, and snippets.

@zhuochun
Forked from elight/dci_alt.rb
Created December 23, 2013 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuochun/8104795 to your computer and use it in GitHub Desktop.
Save zhuochun/8104795 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
# ... lots of persistence stuff
end
class GitHubUserProvisioner < SimpleDelegator
def provision_with!(user_info, extra_user_hash)
self.github_login = extra_user_hash['login']
self.name = user_info['name']
self.email = user_info['email']
self.github_url = user_info['urls']['GitHub']
self.blog_url = user_info['urls']['Blog']
self.gravatar_id = extra_user_hash['gravatar_id']
self.location = extra_user_hash['location']
save!
end
end
# And, say, in your SessionController in your controller action
class SessionController < ApplicationController
def create
user = User.new
provisioner = GitHubUserProvisioner.new(user)
provisioner.provision_with!(*yank_oauth_stuff_off_request)
end
private
def yank_oauth_stuff_off_request
# ...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment