module Sequel::Simple::OAuth2::Client
Client
role mixin for Sequel
. Includes all the required API, associations, validations and callbacks.
Public Class Methods
by_key(key)
click to toggle source
Searches for Client
record with the specific `#key` value.
@param key [#to_s] key value (any object that responds to `#to_s`).
@return [Object, nil] Client
object or nil if there is no record with such `#key`.
# File lib/sequel_simple_oauth2/mixins/client.rb, line 46 def self.by_key(key) first(key: key.to_s) end
Public Instance Methods
before_validation()
click to toggle source
Calls superclass method
# File lib/sequel_simple_oauth2/mixins/client.rb, line 27 def before_validation # Generate tokens generate_tokens if new? super end
generate_tokens()
click to toggle source
Generate tokens
@return token [String] string object. @return refresh_token [String] string object.
# File lib/sequel_simple_oauth2/mixins/client.rb, line 57 def generate_tokens self.key = ::Simple::OAuth2::UniqToken.generate if key.blank? self.secret = ::Simple::OAuth2::UniqToken.generate if secret.blank? end
validate()
click to toggle source
Required fields!
Calls superclass method
# File lib/sequel_simple_oauth2/mixins/client.rb, line 34 def validate super validates_presence %i[key secret] validates_unique %i[key secret] end