Module: Bsm::Sso::Client::Cached::ActiveRecord::ClassMethods

Defined in:
lib/bsm/sso/client/cached/active_record.rb

Instance Method Summary collapse

Instance Method Details

#sso_authorize(token) ⇒ Object

Cache!



19
20
21
22
23
24
25
# File 'lib/bsm/sso/client/cached/active_record.rb', line 19

def sso_authorize(token)
  return nil if token.blank?

  relation = where(arel_table[:updated_at].gt(Bsm::Sso::Client.expire_after.ago))
  relation = relation.where(authentication_token: token)
  relation.first || super
end

#sso_cache(resource, _action = nil) ⇒ Object

Cache!



28
29
30
31
32
33
34
# File 'lib/bsm/sso/client/cached/active_record.rb', line 28

def sso_cache(resource, _action=nil)
  record = where(id: resource.id).first_or_initialize
  attrs  = [resource.attributes.slice(*record.attribute_names)]
  record.assign_attributes(*attrs)
  record.changed? ? record.save! : record.touch
  record
end

#sso_find(id) ⇒ Object

Retrieve cached



14
15
16
# File 'lib/bsm/sso/client/cached/active_record.rb', line 14

def sso_find(id)
  where(id: id).first || super
end