@@ -4,23 +4,31 @@ module OmniAuth
4
4
module Identity
5
5
# This module provides an includable interface for implementing the
6
6
# 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
+ #
10
23
module Model
24
+ SCHEMA_ATTRIBUTES = %w[ name email nickname first_name last_name location description image phone ] . freeze
25
+
11
26
def self . included ( base )
12
27
base . extend ClassMethods
13
28
end
14
29
15
30
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
24
32
25
33
# Authenticate a user with the given key and password.
26
34
#
@@ -43,6 +51,53 @@ def auth_key(method = false)
43
51
44
52
@auth_key || 'email'
45
53
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
46
101
end
47
102
48
103
# Returns self if the provided password is correct, false
@@ -55,22 +110,6 @@ def authenticate(password)
55
110
raise NotImplementedError
56
111
end
57
112
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
-
74
113
# An identifying string that must be globally unique to the
75
114
# application. Defaults to stringifying the `id` method.
76
115
#
@@ -113,6 +152,21 @@ def auth_key=(value)
113
152
raise NotImplementedError
114
153
end
115
154
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
116
170
end
117
171
end
118
172
end
0 commit comments