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
81 82 83 84 85 86 87 88 |
# File 'app/models/permalink.rb', line 81 def self.filter_by(url = nil) permalinks = Permalink.includes(:topic, :post, :category, :tag).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
64 65 66 |
# File 'app/models/permalink.rb', line 64 def self.find_by_url(url) find_by(url: normalize_url(url)) end |
.normalize_url(url) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/permalink.rb', line 51 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
#normalize_url ⇒ Object
68 69 70 |
# File 'app/models/permalink.rb', line 68 def normalize_url self.url = Permalink.normalize_url(url) if url end |