Class: Permalink
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Permalink
- Defined in:
- app/models/permalink.rb
Defined Under Namespace
Classes: Normalizer
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.filter_by(url = nil) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'app/models/permalink.rb', line 80 def self.filter_by(url = nil) permalinks = Permalink.includes(:topic, :post, :category, :tag, :user).order("permalinks.created_at desc") permalinks.where!("url ILIKE :url OR external_url ILIKE :url", url: "%#{url}%") if url.present? permalinks.limit!(100) permalinks.to_a end |
.find_by_url(url) ⇒ Object
66 67 68 |
# File 'app/models/permalink.rb', line 66 def self.find_by_url(url) find_by(url: normalize_url(url)) end |
.normalize_url(url) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/permalink.rb', line 53 def self.normalize_url(url) if url url = url.strip url = url[1..-1] if url[0, 1] == "/" end normalizations = SiteSetting.permalink_normalizations @normalizer = Normalizer.new(normalizations) unless @normalizer && @normalizer.source == normalizations @normalizer.normalize(url) end |
Instance Method Details
#target_url ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/models/permalink.rb', line 70 def target_url return relative_external_url if external_url return post.relative_url if post return topic.relative_url if topic return category.relative_url if category return tag.relative_url if tag return user.relative_url if user nil end |