Skip to content

Commit

Permalink
Rename enum_value => site_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Oct 6, 2023
1 parent 42aa471 commit d086408
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/helpers/artist_url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def submission_url(submission)
end

def site_types_collection
Sites.definitions.map { |definitions| [definitions.display_name, definitions.enum_value] }.sort
Sites.definitions.map { |definition| [definition.display_name, definition.site_type] }.sort
end

def site_icon(artist_url)
Expand Down
2 changes: 1 addition & 1 deletion app/logical/sites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Sites
module_function

def from_enum(value)
definitions.find { |definition| definition.enum_value == value }
definitions.find { |definition| definition.site_type == value }
end

def from_gallery_url(url)
Expand Down
4 changes: 2 additions & 2 deletions app/logical/sites/scraper_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(definition_data)
@submission_template = Addressable::Template.new(definition_data["submission_template"])
@image_domains = definition_data["image_domains"] || []
@download_headers = definition_data["download_headers"] || {}
@scraper = "Scraper::#{enum_value.camelize}".constantize
@scraper = "Scraper::#{site_type.camelize}".constantize
end

def submission_url(submission)
Expand All @@ -35,7 +35,7 @@ def cached_values
end

def manually_disabled?
Config.send("#{enum_value}_disabled?")
Config.send("#{site_type}_disabled?")
end

def scraper_enabled?
Expand Down
6 changes: 3 additions & 3 deletions app/logical/sites/simple_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module Sites
class SimpleDefinition
attr_reader :enum_value, :display_name, :homepage, :gallery_templates, :username_identifier_regex, :image_domains, :download_headers
attr_reader :site_type, :display_name, :homepage, :gallery_templates, :username_identifier_regex, :image_domains, :download_headers

def initialize(definition_data)
@enum_value = definition_data["enum_value"]
@site_type = definition_data["enum_value"]
@display_name = definition_data["display_name"]
@homepage = definition_data["homepage"]
@gallery_templates = definition_data["gallery_templates"].map { |t| Addressable::Template.new("{prefix}#{t}{/remaining}{?remaining}{#remaining}") }
Expand All @@ -32,7 +32,7 @@ def handles_image_domain?(domain)
end

def icon_class
"site-icon-#{enum_value.starts_with?('youtube') ? 'youtube' : enum_value}"
"site-icon-#{site_type.starts_with?('youtube') ? 'youtube' : site_type}"
end

def gallery_url(identifier)
Expand Down
2 changes: 1 addition & 1 deletion app/models/artist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def add_artist_url(url)
end

artist_url = artist_urls.new(
site_type: result[:site].enum_value,
site_type: result[:site].site_type,
url_identifier: result[:identifier],
created_at_on_site: Time.current,
about_on_site: "",
Expand Down
2 changes: 1 addition & 1 deletion app/views/config/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
<% end %>

<% Sites.scraper_definitions.each do |definition| %>
<div><%= link_to "#{definition.display_name} settings", config_path(definition.enum_value) %></div>
<div><%= link_to "#{definition.display_name} settings", config_path(definition.site_type) %></div>
<% end %>
4 changes: 2 additions & 2 deletions app/views/config/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<%= link_to @definition.homepage, @definition.homepage %><br>
<%= simple_form_for(:config, url: modify_config_index_path, method: :put) do |f| %>
<% @definition.all_config_keys.each do |key| %>
<%= f.input key, label: key.to_s.delete_prefix("#{@definition.enum_value}_"), input_html: { value: Config.send(key) } %>
<%= f.input key, label: key.to_s.delete_prefix("#{@definition.site_type}_"), input_html: { value: Config.send(key) } %>
<% end %>
<%= f.input "#{@definition.enum_value}_disabled", as: :select, label: "disabled", selected: Config.send("#{@definition.enum_value}_disabled?").to_s %>
<%= f.input "#{@definition.site_type}_disabled", as: :select, label: "disabled", selected: Config.send("#{@definition.site_type}_disabled?").to_s %>
<%= f.submit %>
<% end %>
12 changes: 6 additions & 6 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
</thead>
<tbody>
<% @definitions.each do |definition| %>
<% entry = @counts[definition.enum_value] || {} %>
<% entry = @counts[definition.site_type] || {} %>
<tr>
<td><%= link_to_if(definition.enum_value != "manual", definition.display_name, config_path(definition.enum_value)) %></td>
<td><%= link_to(entry["artist_count"] || 0, artists_path(search: { site_type: definition.enum_value })) %></td>
<td><%= link_to(entry["url_count"] || 0, artist_urls_path(search: { site_type: definition.enum_value })) %></td>
<td><%= link_to(entry["submission_count"] || 0, submission_files_path(search: { site_type: definition.enum_value })) %></td>
<td><%= link_to(entry["file_count"] || 0, submission_files_path(search: { site_type: definition.enum_value })) %></td>
<td><%= link_to_if(definition.site_type != "manual", definition.display_name, config_path(definition.site_type)) %></td>
<td><%= link_to(entry["artist_count"] || 0, artists_path(search: { site_type: definition.site_type })) %></td>
<td><%= link_to(entry["url_count"] || 0, artist_urls_path(search: { site_type: definition.site_type })) %></td>
<td><%= link_to(entry["submission_count"] || 0, submission_files_path(search: { site_type: definition.site_type })) %></td>
<td><%= link_to(entry["file_count"] || 0, submission_files_path(search: { site_type: definition.site_type })) %></td>
<td>
<% if definition.manually_disabled? %>
Manually disabled
Expand Down
2 changes: 1 addition & 1 deletion app/views/submission_files/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
<% end %>
</div>

<% page_title "#{@submission_file.artist.name} on #{@submission_file.artist_url.site.enum_value}" %>
<% page_title "#{@submission_file.artist.name} on #{@submission_file.artist_url.site.display_name}" %>
4 changes: 2 additions & 2 deletions test/logical/scraper/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
module Scraper
class BaseTest < ActiveSupport::TestCase
Sites.scraper_definitions.each do |definition|
test "#{definition.enum_value} has correct state" do
scraper = stub_scraper_enabled(definition.enum_value) { definition.new_scraper(build(:artist_url)) }
test "#{definition.site_type} has correct state" do
scraper = stub_scraper_enabled(definition.site_type) { definition.new_scraper(build(:artist_url)) }
assert_respond_to(scraper.class, :state)
assert(scraper.instance_variable_defined?(:"@#{scraper.class.state}"))
end
Expand Down
10 changes: 5 additions & 5 deletions test/logical/sites_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,30 @@ def expect_correct_escaping(input, output)
end

describe "from_gallery_url" do
def assert_extracted(url:, site:, username:, valid: true)
def assert_extracted(url:, site_type:, username:, valid: true)
result = Sites.from_gallery_url(url)
assert(result)
assert_equal(site, result[:site].enum_value)
assert_equal(site_type, result[:site].site_type)
assert_equal(username, result[:identifier])
assert_equal(valid, result[:valid])
end

it "correctly extracts information from twitter" do
assert_extracted(
url: "https://twitter.com/username",
site: "twitter",
site_type: "twitter",
username: "username",
)

assert_extracted(
url: "https://twitter.com/@username",
site: "twitter",
site_type: "twitter",
username: "username",
)

assert_extracted(
url: "https://twitter.com/!invalid!",
site: "twitter",
site_type: "twitter",
username: "!invalid!",
valid: false,
)
Expand Down

0 comments on commit d086408

Please sign in to comment.