Module: HasTokenId::Concern::ClassMethods
- Defined in:
- lib/has_token_id/concern.rb
Instance Method Summary collapse
-
#default_token_options ⇒ Object
Default options as well as an overwrite point so you can assign different defaults to different models.
-
#generate_unique_token ⇒ Object
Generates a unique token based on the options.
Instance Method Details
#default_token_options ⇒ Object
Default options as well as an overwrite point so you can assign different defaults to different models
16 17 18 19 20 21 22 |
# File 'lib/has_token_id/concern.rb', line 16 def @default_token_options ||= begin = HasTokenId. [:prefix] ||= self.name[0, 1] end end |
#generate_unique_token ⇒ Object
Generates a unique token based on the options
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/has_token_id/concern.rb', line 25 def generate_unique_token record, = true, @has_token_id_options conditions = {} while record token = [ [:prefix], Digest::SHA1.hexdigest((Time.now.to_i * rand()).to_s)].compact.join[0...[:length].to_i] conditions[[:param_name].to_sym] = token record = self.where(conditions).first end token end |