module HasTokenable::FinderMethods
Public Instance Methods
find(*args)
click to toggle source
Find by token if the first param looks like a token, otherwise use super
Calls superclass method
# File lib/has_tokenable/finder_methods.rb, line 24 def find(*args) if args[0].is_a?(String) && args[0].length == has_tokenable_options[:length] record = find_by_token(args[0]) end record || super(*args) end
find!(*args)
click to toggle source
# File lib/has_tokenable/finder_methods.rb, line 31 def find!(*args) record = find(*args) raise ActiveRecord::RecordNotFound if record.nil? record end
find_by_case_sensitive_token(token)
click to toggle source
Find by token ensuring case sensitivity
# File lib/has_tokenable/finder_methods.rb, line 5 def find_by_case_sensitive_token(token) return if token.nil? where("#{token_with_table_name} = ?", token).first end
find_by_token(token)
click to toggle source
Find by token
# File lib/has_tokenable/finder_methods.rb, line 11 def find_by_token(token) return if token.nil? send(:find_by_case_sensitive_token , token) end
find_by_token!(token)
click to toggle source
Find by token and raise error if no record is found
# File lib/has_tokenable/finder_methods.rb, line 17 def find_by_token!(token) record = find_by_token(token) raise ActiveRecord::RecordNotFound, "Could not find #{self.name} with token #{token.inspect}" if record.nil? record end
Private Instance Methods
token_with_table_name()
click to toggle source
# File lib/has_tokenable/finder_methods.rb, line 39 def token_with_table_name "#{table_name}.#{has_tokenable_options[:param_name]}" end