Module: Challah::Authorizeable::ClassMethods
- Defined in:
- lib/challah/concerns/authorizeable.rb
Instance Method Summary collapse
-
#del(options = {}) ⇒ Object
Remove an authorization.
-
#get(options = {}) ⇒ Object
Grab the user/provider record.
- #hashable_attributes ⇒ Object
-
#set(options = {}) ⇒ Object
Create a new authorization record for the given user.
- #user_model ⇒ Object
- #users_table_name ⇒ Object
Instance Method Details
#del(options = {}) ⇒ Object
Remove an authorization
21 22 23 24 25 26 |
# File 'lib/challah/concerns/authorizeable.rb', line 21 def del( = {}) provider = .fetch(:provider) user_id = .fetch(:user_id) where(provider: provider, user_id: user_id).delete_all end |
#get(options = {}) ⇒ Object
Grab the user/provider record
29 30 31 32 33 34 |
# File 'lib/challah/concerns/authorizeable.rb', line 29 def get( = {}) provider = .fetch(:provider) user_id = .fetch(:user_id) where(provider: provider, user_id: user_id).first end |
#hashable_attributes ⇒ Object
15 16 17 18 |
# File 'lib/challah/concerns/authorizeable.rb', line 15 def hashable_attributes protected_attributes = %w( user_id provider last_session_at last_session_ip session_count created_at updated_at ) @hashable_attributes ||= self.columns.map(&:name) - protected_attributes end |
#set(options = {}) ⇒ Object
Create a new authorization record for the given user
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/challah/concerns/authorizeable.rb', line 37 def set( = {}) provider = .delete(:provider) user_id = .delete(:user_id).to_i uid = .delete(:uid) token = .delete(:token) expires_at = .delete(:expires_at) || nil del(provider: provider, user_id: user_id) record = self.new() record.provider = provider record.user_id = user_id record.uid = uid record.token = token record.expires_at = expires_at record.attributes = if .any? record.save! record end |
#user_model ⇒ Object
63 64 65 |
# File 'lib/challah/concerns/authorizeable.rb', line 63 def user_model @user_model ||= Challah.user end |
#users_table_name ⇒ Object
59 60 61 |
# File 'lib/challah/concerns/authorizeable.rb', line 59 def users_table_name @users_table_name ||= user_model.table_name end |