Skip to content

Instantly share code, notes, and snippets.

@r38y
Created December 15, 2009 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save r38y/257242 to your computer and use it in GitHub Desktop.
Save r38y/257242 to your computer and use it in GitHub Desktop.
# any idea how I could protect find_then_update_or_create_from_has with
# protect_from_non_user_hash by getting it to return what protect_from_non_user_hash
# returns?
# Basically use protect_from_non_user_hash to stop find_then_update_or_create_from_hash
class User < ActiveRecord::Base
def self.protect_from_non_user_hash(hash)
return nil if !hash.is_a?(Hash) || hash['error']
end
def self.find_then_update_or_create_from_hash(hash)
protect_from_non_user_hash(hash)
user = find_by_bsso_uuid(hash['uuid'])
if user.blank?
user = create_from_hash(hash)
else
user.update_from_hash(hash)
end
user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment