Skip to content

Commit e01bed8

Browse files
committed
Rubocop fixes
1 parent 3d1076f commit e01bed8

File tree

11 files changed

+101
-70
lines changed

11 files changed

+101
-70
lines changed

app/jobs/better_together/metrics/rich_text_external_link_checker_queue_job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
24
module Metrics
35
class RichTextExternalLinkCheckerQueueJob < RichTextLinkCheckerQueueJob

app/jobs/better_together/metrics/rich_text_internal_link_checker_queue_job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
24
module Metrics
35
class RichTextInternalLinkCheckerQueueJob < RichTextLinkCheckerQueueJob

app/jobs/better_together/metrics/rich_text_link_checker_queue_job.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
24
module Metrics
35
class RichTextLinkCheckerQueueJob < MetricsJob
4-
56
def perform
67
records_size = model_collection.size
78
return if records_size.zero?
@@ -44,7 +45,7 @@ def queue_jobs_for_host(host, delay_between_requests)
4445

4546
def child_job_class
4647
# Define this in subclasses (e.g., InternalLinkCheckerJob, ExternalLinkCheckerJob)
47-
raise NotImplementedError, "Subclasses must implement `child_job_class`"
48+
raise NotImplementedError, 'Subclasses must implement `child_job_class`'
4849
end
4950

5051
def last_checked_lt
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
2-
class Content::Link < ApplicationRecord
3-
has_many :rich_text_links, class_name: 'BetterTogether::Metrics::RichTextLink', inverse_of: :link
4-
has_many :rich_texts, through: :rich_text_links
5-
has_many :rich_text_records, through: :rich_text_links
4+
module Content
5+
class Link < ApplicationRecord
6+
has_many :rich_text_links, class_name: 'BetterTogether::Metrics::RichTextLink', inverse_of: :link
7+
has_many :rich_texts, through: :rich_text_links
8+
has_many :rich_text_records, through: :rich_text_links
9+
end
610
end
711
end
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
24
module Links
35
def self.table_name_prefix
4-
"better_together_links_"
6+
'better_together_links_'
57
end
68
end
79
end
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
2-
class Metrics::RichTextLink < ApplicationRecord
3-
belongs_to :link, class_name: 'BetterTogether::Content::Link'
4-
belongs_to :rich_text, class_name: 'ActionText::RichText'
5-
belongs_to :rich_text_record, polymorphic: true
4+
module Metrics
5+
class RichTextLink < ApplicationRecord
6+
belongs_to :link, class_name: 'BetterTogether::Content::Link'
7+
belongs_to :rich_text, class_name: 'ActionText::RichText'
8+
belongs_to :rich_text_record, polymorphic: true
69

7-
accepts_nested_attributes_for :link, reject_if: ->(attributes){ attributes['url'].blank? }, allow_destroy: false
10+
accepts_nested_attributes_for :link, reject_if: ->(attributes) { attributes['url'].blank? }, allow_destroy: false
11+
end
812
end
913
end

db/migrate/20241124181740_create_better_together_content_links.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class CreateBetterTogetherContentLinks < ActiveRecord::Migration[7.1]
24
def change
35
create_bt_table :links, prefix: :better_together_content do |t|

db/migrate/20241125190948_create_better_together_metrics_rich_text_links.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class CreateBetterTogetherMetricsRichTextLinks < ActiveRecord::Migration[7.1]
24
def change
35
create_bt_table :rich_text_links, prefix: :better_together_metrics do |t|
@@ -8,7 +10,7 @@ def change
810
t.bt_position # index in the RichText links array
911
t.bt_locale # locale of the RichText content
1012

11-
t.index [:rich_text_id, :position, :locale], unique: true
13+
t.index %i[rich_text_id position locale], unique: true
1214
end
1315
end
1416
end

lib/tasks/quality_assurance.rake

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
namespace :better_together do
24
namespace :qa do
35
namespace :rich_text do
@@ -20,58 +22,15 @@ namespace :better_together do
2022
next unless links.any?
2123

2224
links.each_with_index do |link, index|
23-
begin
24-
uri = URI.parse(link)
25-
26-
internal_link = uri.host == platform_uri.host
27-
link_type = determine_link_type(uri, internal_link)
28-
29-
if uri.host.nil? && uri.scheme.nil?
30-
invalid_type = if uri.path
31-
'path'
32-
elsif link.include?('mailto')
33-
'email'
34-
elsif link.include?('tel')
35-
'phone'
36-
else
37-
'undetermined'
38-
end
39-
40-
invalid_rich_text_links << {
41-
rich_text_id: rt.id,
42-
rich_text_record_id: rt.record_id,
43-
rich_text_record_type: rt.record_type,
44-
locale: rt.locale,
45-
position: index, # Track the first position for clarity
46-
47-
link_attributes: {
48-
url: link,
49-
link_type: "invalid:#{invalid_type}",
50-
valid_link: false,
51-
error_message: 'No host or scheme. Needs review.'
52-
}
53-
}
25+
uri = URI.parse(link)
5426

55-
next
56-
end
27+
internal_link = uri.host == platform_uri.host
28+
link_type = determine_link_type(uri, internal_link)
5729

58-
valid_rich_text_links << {
59-
rich_text_id: rt.id,
60-
rich_text_record_id: rt.record_id,
61-
rich_text_record_type: rt.record_type,
62-
locale: rt.locale,
63-
position: index, # Track the first position for clarity
64-
65-
link_attributes: {
66-
url: link,
67-
host: uri.host,
68-
link_type: link_type,
69-
valid_link: true,
70-
external: !internal_link
71-
}
72-
}
73-
rescue URI::InvalidURIError => e
74-
invalid_type = if link.include?('mailto')
30+
if uri.host.nil? && uri.scheme.nil?
31+
invalid_type = if uri.path
32+
'path'
33+
elsif link.include?('mailto')
7534
'email'
7635
elsif link.include?('tel')
7736
'phone'
@@ -90,25 +49,75 @@ namespace :better_together do
9049
url: link,
9150
link_type: "invalid:#{invalid_type}",
9251
valid_link: false,
93-
error_message: e.message,
52+
error_message: 'No host or scheme. Needs review.'
9453
}
9554
}
55+
56+
next
9657
end
58+
59+
valid_rich_text_links << {
60+
rich_text_id: rt.id,
61+
rich_text_record_id: rt.record_id,
62+
rich_text_record_type: rt.record_type,
63+
locale: rt.locale,
64+
position: index, # Track the first position for clarity
65+
66+
link_attributes: {
67+
url: link,
68+
host: uri.host,
69+
link_type: link_type,
70+
valid_link: true,
71+
external: !internal_link
72+
}
73+
}
74+
rescue URI::InvalidURIError => e
75+
invalid_type = if link.include?('mailto')
76+
'email'
77+
elsif link.include?('tel')
78+
'phone'
79+
else
80+
'undetermined'
81+
end
82+
83+
invalid_rich_text_links << {
84+
rich_text_id: rt.id,
85+
rich_text_record_id: rt.record_id,
86+
rich_text_record_type: rt.record_type,
87+
locale: rt.locale,
88+
position: index, # Track the first position for clarity
89+
90+
link_attributes: {
91+
url: link,
92+
link_type: "invalid:#{invalid_type}",
93+
valid_link: false,
94+
error_message: e.message
95+
}
96+
}
9797
end
9898
end
9999

100100
# Upsert valid and invalid links
101-
BetterTogether::Metrics::RichTextLink.upsert_all(valid_rich_text_links, unique_by: %i[rich_text_id position locale]) if valid_rich_text_links.any?
102-
BetterTogether::Metrics::RichTextLink.upsert_all(invalid_rich_text_links, unique_by: %i[rich_text_id position locale]) if invalid_rich_text_links.any?
101+
if valid_rich_text_links.any?
102+
BetterTogether::Metrics::RichTextLink.upsert_all(valid_rich_text_links,
103+
unique_by: %i[rich_text_id position
104+
locale])
105+
end
106+
if invalid_rich_text_links.any?
107+
BetterTogether::Metrics::RichTextLink.upsert_all(invalid_rich_text_links,
108+
unique_by: %i[rich_text_id position
109+
locale])
110+
end
103111

104112
puts "Valid links processed: #{valid_rich_text_links.size}"
105113
puts "Invalid links processed: #{invalid_rich_text_links.size}"
106114
end
107115

108116
desc 'checks rich text links and returns their status code'
109117
task check: :environment do
110-
internal_queue_job = BetterTogether::Metrics::RichTextInternalLinkCheckerQueueJob.new
111-
external_queue_job = BetterTogether::Metrics::RichTextExternalLinkCheckerQueueJob.new; byebug
118+
BetterTogether::Metrics::RichTextInternalLinkCheckerQueueJob.new
119+
BetterTogether::Metrics::RichTextExternalLinkCheckerQueueJob.new
120+
byebug
112121
end
113122

114123
def determine_link_type(uri, internal_link)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# frozen_string_literal: true
2+
13
FactoryBot.define do
24
factory :metrics_rich_text_link, class: 'Metrics::RichTextLink' do
3-
45
end
56
end

0 commit comments

Comments
 (0)