Class: Redirect
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Redirect
show all
- Includes:
- StringLengthLimit
- Defined in:
- app/models/redirect.rb
Constant Summary
StringLengthLimit::STRING_LIMIT
Instance Method Summary
collapse
Instance Method Details
#from_url ⇒ Object
39
40
41
|
# File 'app/models/redirect.rb', line 39
def from_url
File.join(blog.shortener_url, from_path)
end
|
#full_to_path ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/models/redirect.rb', line 15
def full_to_path
path = to_path
return path if %r{^(https?)://([^/]*)(.*)}.match?(path)
url_root = blog.root_path
unless url_root.nil? || path[0, url_root.length] == url_root
path = File.join(url_root, path)
end
path
end
|
#shorten ⇒ Object
27
28
29
30
31
32
33
|
# File 'app/models/redirect.rb', line 27
def shorten
if (temp_token = random_token) && self.class.find_by(from_path: temp_token).nil?
temp_token
else
shorten
end
end
|
#to_url ⇒ Object
35
36
37
|
# File 'app/models/redirect.rb', line 35
def to_url
raise "Use #from_url"
end
|