Module: ActsAsTokened::FinderMethods

Defined in:
app/models/concerns/acts_as_tokened.rb

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/concerns/acts_as_tokened.rb', line 28

def find(*args)
  return super unless args.length == 1
  return super if block_given?

  reloading = instance_variable_get(:@_effective_reloading)
  reloading ||= self.class.instance_variable_get(:@_effective_reloading)
  reloading ||= klass.instance_variable_get(:@_effective_reloading) if respond_to?(:klass)

  return find_by_id(args.first) if reloading

  find_by_token(args.first) || raise(::ActiveRecord::RecordNotFound.new("Couldn't find #{name} with 'token'=#{args.first}"))
end