Class: Orthoses::ActiveRecord::SecureToken

Inherits:
Object
  • Object
show all
Defined in:
lib/orthoses/active_record/secure_token.rb

Overview

def has_secure_token(attribute = :token, length: MINIMUM_TOKEN_LENGTH)

Instance Method Summary collapse

Constructor Details

#initialize(loader) ⇒ SecureToken

Returns a new instance of SecureToken.



7
8
9
# File 'lib/orthoses/active_record/secure_token.rb', line 7

def initialize(loader)
  @loader = loader
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/orthoses/active_record/secure_token.rb', line 11

def call
  has_secure_token = CallTracer::Lazy.new
  store = has_secure_token.trace('ActiveRecord::SecureToken::ClassMethods#has_secure_token') do
    @loader.call
  end

  has_secure_token.captures.each do |capture|
    base_name = Utils.module_name(capture.method.receiver) or next
    attribute = capture.argument[:attribute]

    store[base_name] << "def regenerate_#{attribute}: () -> bool"
  end

  store
end