Class: Redirect
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Redirect
- Defined in:
- app/models/redirect.rb
Instance Method Summary collapse
Instance Method Details
#from_url ⇒ Object
35 36 37 |
# File 'app/models/redirect.rb', line 35 def from_url File.join(blog.shortener_url, from_path) end |
#full_to_path ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/redirect.rb', line 11 def full_to_path path = to_path # FIXME: Unify HTTP URI matchers 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
23 24 25 26 27 28 29 |
# File 'app/models/redirect.rb', line 23 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
31 32 33 |
# File 'app/models/redirect.rb', line 31 def to_url raise "Use #from_url" end |