Module: Socialite::Models::IdentityConcern::ClassMethods

Defined in:
lib/socialite/models/identity_concern.rb

Instance Method Summary collapse

Instance Method Details

#create_from_omniauth(auth = {}) ⇒ Object

Finder method that finds the matching Provider and Unique ID or initializes a new, unsaved, object.


12
13
14
15
16
17
18
# File 'lib/socialite/models/identity_concern.rb', line 12

def create_from_omniauth(auth={})
  create do |identity|
    identity.provider = auth['provider']
    identity.uid = auth['uid']
    identity.auth_hash = auth
  end
end

#find_from_omniauth(auth = {}) ⇒ Object

Finder method that finds the matching Provider and UID.


28
29
30
# File 'lib/socialite/models/identity_concern.rb', line 28

def find_from_omniauth(auth={})
  where(:provider => auth['provider'], :uid => auth['uid']).first
end

#find_or_create_from_omniauth(auth) ⇒ Object

Raises:

  • (ArgumentError)

20
21
22
23
# File 'lib/socialite/models/identity_concern.rb', line 20

def find_or_create_from_omniauth(auth)
  raise ArgumentError, 'auth parameter must be a hash' unless auth.is_a?(Hash)
  find_from_omniauth(auth) || create_from_omniauth(auth)
end