@@ -4,23 +4,31 @@ module OmniAuth
44 module Identity
55 # This module provides an includable interface for implementing the
66 # necessary API for OmniAuth Identity to properly locate identities
7- # and provide all necessary information. All methods marked as
8- # abstract must be implemented in the including class for things to
9- # work properly.
7+ # and provide all necessary information.
8+ #
9+ # All methods marked as abstract must be implemented in the
10+ # including class for things to work properly.
11+ #
12+ ### Singleton API
13+ #
14+ # * locate(key)
15+ # * create(*args) - Deprecated in v3.0.5; Will be removed in v4.0
16+ #
17+ ### Instance API
18+ #
19+ # * save
20+ # * persisted?
21+ # * authenticate(password)
22+ #
1023 module Model
24+ SCHEMA_ATTRIBUTES = %w[ name email nickname first_name last_name location description image phone ] . freeze
25+
1126 def self . included ( base )
1227 base . extend ClassMethods
1328 end
1429
1530 module ClassMethods
16- # Locate an identity given its unique login key.
17- #
18- # @abstract
19- # @param [String] key The unique login key.
20- # @return [Model] An instance of the identity model class.
21- def locate ( key )
22- raise NotImplementedError
23- end
31+ extend Gem ::Deprecate
2432
2533 # Authenticate a user with the given key and password.
2634 #
@@ -43,6 +51,53 @@ def auth_key(method = false)
4351
4452 @auth_key || 'email'
4553 end
54+
55+ # Persists a new Identity object to the ORM.
56+ # Defaults to calling super. Override as needed per ORM.
57+ #
58+ # @deprecated v4.0 will begin using {#new} with {#save} instead.
59+ # @abstract
60+ # @param [Hash] args Attributes of the new instance.
61+ # @return [Model] An instance of the identity model class.
62+ # @since 3.0.5
63+ def create ( *args )
64+ raise NotImplementedError unless defined? ( super )
65+
66+ super
67+ end
68+
69+ # Locate an identity given its unique login key.
70+ #
71+ # @abstract
72+ # @param [String] key The unique login key.
73+ # @return [Model] An instance of the identity model class.
74+ def locate ( key )
75+ raise NotImplementedError
76+ end
77+ end
78+
79+ # Persists a new Identity object to the ORM.
80+ # Default raises an error. Override as needed per ORM.
81+ #
82+ # @abstract
83+ # @return [Model] An instance of the identity model class.
84+ # @since 3.0.5
85+ def save
86+ raise NotImplementedError unless defined? ( super )
87+
88+ super
89+ end
90+
91+ # Checks if the Identity object is persisted in the ORM.
92+ # Defaults to calling super. Override as needed per ORM.
93+ #
94+ # @abstract
95+ # @return [true or false] true if object exists, false if not.
96+ # @since 3.0.5
97+ def persisted?
98+ raise NotImplementedError unless defined? ( super )
99+
100+ super
46101 end
47102
48103 # Returns self if the provided password is correct, false
@@ -55,22 +110,6 @@ def authenticate(password)
55110 raise NotImplementedError
56111 end
57112
58- SCHEMA_ATTRIBUTES = %w[ name email nickname first_name last_name location description image phone ] . freeze
59- # A hash of as much of the standard OmniAuth schema as is stored
60- # in this particular model. By default, this will call instance
61- # methods for each of the attributes it needs in turn, ignoring
62- # any for which `#respond_to?` is `false`.
63- #
64- # If `first_name`, `nickname`, and/or `last_name` is provided but
65- # `name` is not, it will be automatically calculated.
66- #
67- # @return [Hash] A string-keyed hash of user information.
68- def info
69- SCHEMA_ATTRIBUTES . each_with_object ( { } ) do |attribute , hash |
70- hash [ attribute ] = send ( attribute ) if respond_to? ( attribute )
71- end
72- end
73-
74113 # An identifying string that must be globally unique to the
75114 # application. Defaults to stringifying the `id` method.
76115 #
@@ -113,6 +152,21 @@ def auth_key=(value)
113152 raise NotImplementedError
114153 end
115154 end
155+
156+ # A hash of as much of the standard OmniAuth schema as is stored
157+ # in this particular model. By default, this will call instance
158+ # methods for each of the attributes it needs in turn, ignoring
159+ # any for which `#respond_to?` is `false`.
160+ #
161+ # If `first_name`, `nickname`, and/or `last_name` is provided but
162+ # `name` is not, it will be automatically calculated.
163+ #
164+ # @return [Hash] A string-keyed hash of user information.
165+ def info
166+ SCHEMA_ATTRIBUTES . each_with_object ( { } ) do |attribute , hash |
167+ hash [ attribute ] = send ( attribute ) if respond_to? ( attribute )
168+ end
169+ end
116170 end
117171 end
118172end
0 commit comments