Skip to content

Commit

Permalink
Don't check against the exact definition classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Oct 13, 2023
1 parent cdf2f89 commit 40b407d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/logical/sites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def definitions
end

def scraper_definitions
definitions.select { |s| s.is_a?(ScraperDefinition) }
definitions.select(&:scraper?)
end

def reset_cache
Expand Down
4 changes: 4 additions & 0 deletions app/logical/sites/scraper_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def scraper_enabled?
missing_config_keys.none? && !manually_disabled?
end

def scraper?
true
end

def new_scraper(artist_url)
raise StandardError, "This scraper is not enabled!" unless scraper_enabled?

Expand Down
4 changes: 4 additions & 0 deletions app/logical/sites/simple_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@ def manually_disabled?
def scraper_enabled?
false
end

def scraper?
false
end
end
end
12 changes: 3 additions & 9 deletions app/models/artist_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,15 @@ def set_api_identifier!
end
end

def site
@site ||= Sites.from_enum(site_type)
end

def unescaped_url_identifier
CGI.unescape(url_identifier)
end

def scraper?
site.is_a?(Sites::ScraperDefinition)
def site
@site ||= Sites.from_enum(site_type)
end

def scraper_enabled?
scraper? && site.scraper_enabled?
end
delegate :scraper?, :scraper_enabled?, to: :site

def scraper
site.new_scraper(self)
Expand Down
4 changes: 2 additions & 2 deletions app/views/stats/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<tbody>
<% @definitions.each do |definition| %>
<% entry = @counts[definition.site_type] || {} %>
<% next if definition.instance_of?(Sites::SimpleDefinition) && !entry["file_count"] %>
<% next unless definition.scraper? || entry["file_count"] %>
<tr>
<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>
Expand All @@ -27,7 +27,7 @@
<% elsif definition.missing_config_keys.any? %>
Missing config <%= "key".pluralize(definition.missing_config_keys.count) %>:<br>
<%= definition.missing_config_keys.join(", ") %>
<% elsif definition.instance_of?(Sites::SimpleDefinition) %>
<% elsif !definition.scraper? %>
Removed
<% else %>
Enabled
Expand Down
4 changes: 2 additions & 2 deletions test/logical/sites_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class SitesTest < ActiveSupport::TestCase
it "returns the correct definition for enum lookups" do
twitter = Sites.from_enum("twitter")
twitch = Sites.from_enum("twitch")
assert_instance_of(Sites::ScraperDefinition, twitter)
assert_predicate(twitter, :scraper?)
assert_equal("Twitter", twitter.display_name)
assert_instance_of(Sites::SimpleDefinition, twitch)
assert_not_predicate(twitch, :scraper?)
assert_equal("Twitch", twitch.display_name)
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def stub_e6(post_id:, iqdb_matches: [], md5: "abc", &)
def stub_scraper_enabled(*site_types, &)
sites = site_types.map { |site_type| Sites.from_enum(site_type.to_s) }
sites.each.with_index do |site, index|
raise ArgumentError, "#{site_types[index]} is not a valid scraper" unless site.is_a?(Sites::ScraperDefinition)
raise ArgumentError, "#{site_types[index]} is not a valid scraper" unless site.scraper?

site.stubs(:scraper_enabled?).returns(true)
end
Expand Down

0 comments on commit 40b407d

Please sign in to comment.