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
38
39
40
|
# File 'app/models/redirect.rb', line 38
def from_url
File.join(blog.shortener_url, from_path)
end
|
#full_to_path ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/models/redirect.rb', line 14
def full_to_path
path = to_path
return path if %r{^(https?)://([^/]*)(.*)}.match?(path)
url_root = blog.root_path
if url_root.length == 0 || path[0, url_root.length] != url_root
path = blog.url_for(path, only_path: true)
end
path
end
|
#shorten ⇒ Object
26
27
28
29
30
31
32
|
# File 'app/models/redirect.rb', line 26
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
34
35
36
|
# File 'app/models/redirect.rb', line 34
def to_url
raise "Use #from_url"
end
|