Class: Darjeelink::ShortLink

Inherits:
ApplicationRecord show all
Defined in:
app/models/darjeelink/short_link.rb

Class Method Summary collapse

Class Method Details

.auto_generate_shortened_pathObject



10
11
12
13
# File 'app/models/darjeelink/short_link.rb', line 10

def self.auto_generate_shortened_path
  # our current db has a case insensitive constraint so we might as well downcase here before we get to db level
  pp SecureRandom.urlsafe_base64(3).downcase
end

.ifind(shortened_path) ⇒ Object



32
33
34
# File 'app/models/darjeelink/short_link.rb', line 32

def ifind(shortened_path)
  where('lower(shortened_path) = ?', shortened_path.downcase).first
end

.search(query) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'app/models/darjeelink/short_link.rb', line 22

def search(query)
  where(
    'shortened_path ILIKE :query', query: "%#{query}%"
  ).or(
    where(
      'url ILIKE :query', query: "%#{query}%"
    )
  )
end