rails: add 'URL' inflection.

Make it so we can write `ArtistURL` instead of `ArtistUrl`.
This commit is contained in:
evazion
2022-02-21 08:41:05 -06:00
parent fbab273c81
commit 60a26af6e3
8 changed files with 16 additions and 14 deletions

View File

@@ -1,10 +1,10 @@
# frozen_string_literal: true
class ArtistUrlsController < ApplicationController
class ArtistURLsController < ApplicationController
respond_to :js, :json, :xml, :html
def index
@artist_urls = ArtistUrl.paginated_search(params)
@artist_urls = ArtistURL.paginated_search(params)
@artist_urls = @artist_urls.includes(:artist) if request.format.html?
respond_with(@artist_urls)

View File

@@ -149,7 +149,7 @@ module ArtistFinder
# @param url [String] the artist profile URL
# @return [Array<Artist>] the list of matching artists
def find_artists(url)
url = ArtistUrl.normalize_normalized_url(url)
url = ArtistURL.normalize_normalized_url(url)
artists = []
while artists.empty? && url.size > 10

View File

@@ -21,7 +21,7 @@ class Artist < ApplicationRecord
after_save :clear_url_string_changed
has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name"
has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl", :autosave => true
has_many :urls, dependent: :destroy, class_name: "ArtistURL", autosave: true
has_many :versions, -> {order("artist_versions.id ASC")}, :class_name => "ArtistVersion"
has_one :wiki_page, -> { active }, foreign_key: "title", primary_key: "name"
has_one :tag_alias, -> { active }, foreign_key: "antecedent_name", primary_key: "name"
@@ -51,7 +51,7 @@ class Artist < ApplicationRecord
url_string_was = url_string
self.urls = string.to_s.scan(/[^[:space:]]+/).map do |url|
is_active, url = ArtistUrl.parse_prefix(url)
is_active, url = ArtistURL.parse_prefix(url)
self.urls.find_or_initialize_by(url: url, is_active: is_active)
end.uniq(&:url)
@@ -238,13 +238,13 @@ class Artist < ApplicationRecord
query = query.strip
if query =~ %r{\A/(.*)/\z}
where(id: ArtistUrl.where_regex(:url, $1).select(:artist_id))
where(id: ArtistURL.where_regex(:url, $1).select(:artist_id))
elsif query.include?("*")
where(id: ArtistUrl.where_like(:url, query).select(:artist_id))
where(id: ArtistURL.where_like(:url, query).select(:artist_id))
elsif query =~ %r{\Ahttps?://}i
ArtistFinder.find_artists(query)
else
where(id: ArtistUrl.where_like(:url, "*#{query}*").select(:artist_id))
where(id: ArtistURL.where_like(:url, "*#{query}*").select(:artist_id))
end
end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
class ArtistUrl < ApplicationRecord
class ArtistURL < ApplicationRecord
normalize :url, :normalize_url
validates :url, presence: true, uniqueness: { scope: :artist_id }