Skip to content

Commit 6037642

Browse files
committed
Rubocop fixes -A
1 parent a6c97fd commit 6037642

File tree

140 files changed

+414
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+414
-133
lines changed

app/concerns/better_together/categorizable.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 Categorizable
35
extend ::ActiveSupport::Concern

app/controllers/better_together/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ApplicationController < ActionController::Base
1616
# before the location can be stored.
1717

1818
before_action do
19-
Rack::MiniProfiler.authorize_request if current_user && current_user.permitted_to?('manage_platform')
19+
Rack::MiniProfiler.authorize_request if current_user&.permitted_to?('manage_platform')
2020
end
2121

2222
rescue_from ActiveRecord::RecordNotFound, with: :handle404

app/controllers/better_together/categories_controller.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
class CategoriesController < FriendlyResourceController
35
before_action :set_model_instance, only: %i[show edit update destroy]

app/controllers/better_together/host_dashboard_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def index # rubocop:todo Metrics/MethodLength
3636

3737
def set_resource_variables(klass, prefix: nil)
3838
variable_name = klass.model_name.name.demodulize.underscore
39-
instance_variable_set(:"@#{prefix + '_' if prefix}#{variable_name.pluralize}",
39+
instance_variable_set(:"@#{"#{prefix}_" if prefix}#{variable_name.pluralize}",
4040
klass.order(created_at: :desc).limit(3))
41-
instance_variable_set(:"@#{prefix + '_' if prefix}#{variable_name}_count", klass.count)
41+
instance_variable_set(:"@#{"#{prefix}_" if prefix}#{variable_name}_count", klass.count)
4242
end
4343
end
4444
end

app/controllers/better_together/metrics/link_clicks_controller.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
# app/controllers/better_together/metrics/link_clicks_controller.rb
24
module BetterTogether
35
module Metrics
Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,81 @@
1-
module BetterTogether
2-
class Metrics::ReportsController < ApplicationController
3-
def index
4-
# Group Page Views by `page_url` and sort by `page_url`
5-
@page_views_by_url = BetterTogether::Metrics::PageView
6-
.group(:page_url)
7-
.order('count_all DESC')
8-
.limit(20)
9-
.count
1+
# frozen_string_literal: true
102

11-
# Use group_by_day from groupdate to group daily Page Views, and sort them automatically by date
12-
@page_views_daily = BetterTogether::Metrics::PageView
13-
.group_by_day(:viewed_at)
14-
.count
3+
module BetterTogether
4+
module Metrics
5+
class ReportsController < ApplicationController
6+
def index
7+
# Group Page Views by `page_url` and sort by `page_url`
8+
@page_views_by_url = BetterTogether::Metrics::PageView
9+
.group(:page_url)
10+
.order('count_all DESC')
11+
.limit(20)
12+
.count
1513

16-
# Group Link Clicks by URL, sorting by URL first
17-
@link_clicks_by_url = BetterTogether::Metrics::LinkClick
18-
.group(:url)
19-
.order('count_all DESC')
20-
.limit(20)
14+
# Use group_by_day from groupdate to group daily Page Views, and sort them automatically by date
15+
@page_views_daily = BetterTogether::Metrics::PageView
16+
.group_by_day(:viewed_at)
2117
.count
2218

23-
# Group Link Clicks by internal/external, sorted by internal status first
24-
@internal_vs_external = BetterTogether::Metrics::LinkClick
25-
.group(:internal)
19+
# Group Link Clicks by URL, sorting by URL first
20+
@link_clicks_by_url = BetterTogether::Metrics::LinkClick
21+
.group(:url)
22+
.order('count_all DESC')
23+
.limit(20)
2624
.count
2725

28-
# Group Link Clicks by the page URL where the click occurred, sorted by `page_url`
29-
@link_clicks_by_page = BetterTogether::Metrics::LinkClick
30-
.group(:page_url)
31-
.count
26+
# Group Link Clicks by internal/external, sorted by internal status first
27+
@internal_vs_external = BetterTogether::Metrics::LinkClick
28+
.group(:internal)
29+
.count
3230

33-
# Group Downloads by file name, sorted by file name first
34-
@downloads_by_file = BetterTogether::Metrics::Download
35-
.group(:file_name)
36-
.count
31+
# Group Link Clicks by the page URL where the click occurred, sorted by `page_url`
32+
@link_clicks_by_page = BetterTogether::Metrics::LinkClick
33+
.group(:page_url)
34+
.count
3735

38-
# Group Shares by platform, sorted by platform first
39-
@shares_by_platform = BetterTogether::Metrics::Share
40-
.group(:platform)
41-
.count
36+
# Group Downloads by file name, sorted by file name first
37+
@downloads_by_file = BetterTogether::Metrics::Download
38+
.group(:file_name)
39+
.count
4240

43-
# Group Shares by both URL and Platform, sorted by URL and Platform first
44-
@shares_by_url_and_platform = BetterTogether::Metrics::Share
45-
.group(:url, :platform)
46-
.count
41+
# Group Shares by platform, sorted by platform first
42+
@shares_by_platform = BetterTogether::Metrics::Share
43+
.group(:platform)
44+
.count
4745

48-
# Transform the data for Chart.js
49-
platforms = BetterTogether::Metrics::Share.distinct.pluck(:platform)
50-
urls = @shares_by_url_and_platform.keys.map { |(url, _platform)| url }.uniq
46+
# Group Shares by both URL and Platform, sorted by URL and Platform first
47+
@shares_by_url_and_platform = BetterTogether::Metrics::Share
48+
.group(:url, :platform)
49+
.count
5150

52-
@shares_data = {
53-
labels: urls,
54-
datasets: platforms.map do |platform|
55-
{
56-
label: platform.capitalize,
57-
backgroundColor: random_color_for_platform(platform),
58-
data: urls.map { |url| @shares_by_url_and_platform.fetch([url, platform], 0) }
59-
}
60-
end
61-
}
62-
end
51+
# Transform the data for Chart.js
52+
platforms = BetterTogether::Metrics::Share.distinct.pluck(:platform)
53+
urls = @shares_by_url_and_platform.keys.map { |(url, _platform)| url }.uniq
54+
55+
@shares_data = {
56+
labels: urls,
57+
datasets: platforms.map do |platform|
58+
{
59+
label: platform.capitalize,
60+
backgroundColor: random_color_for_platform(platform),
61+
data: urls.map { |url| @shares_by_url_and_platform.fetch([url, platform], 0) }
62+
}
63+
end
64+
}
65+
end
6366

64-
# A helper method to generate a random color for each platform (this can be customized).
65-
def random_color_for_platform(platform)
66-
colors = {
67-
'facebook' => 'rgba(59, 89, 152, 0.5)',
68-
'twitter' => 'rgba(29, 161, 242, 0.5)',
69-
'linkedin' => 'rgba(0, 123, 182, 0.5)',
70-
'pinterest' => 'rgba(189, 8, 28, 0.5)',
71-
'reddit' => 'rgba(255, 69, 0, 0.5)',
72-
'whatsapp' => 'rgba(37, 211, 102, 0.5)'
73-
}
74-
colors[platform] || 'rgba(75, 192, 192, 0.5)'
67+
# A helper method to generate a random color for each platform (this can be customized).
68+
def random_color_for_platform(platform)
69+
colors = {
70+
'facebook' => 'rgba(59, 89, 152, 0.5)',
71+
'twitter' => 'rgba(29, 161, 242, 0.5)',
72+
'linkedin' => 'rgba(0, 123, 182, 0.5)',
73+
'pinterest' => 'rgba(189, 8, 28, 0.5)',
74+
'reddit' => 'rgba(255, 69, 0, 0.5)',
75+
'whatsapp' => 'rgba(37, 211, 102, 0.5)'
76+
}
77+
colors[platform] || 'rgba(75, 192, 192, 0.5)'
78+
end
7579
end
7680
end
7781
end

app/controllers/better_together/metrics/shares_controller.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
# app/controllers/better_together/metrics/shares_controller.rb
24
module BetterTogether
35
module Metrics

app/controllers/better_together/navigation_items_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def set_pages
102102
end
103103

104104
def set_navigation_area
105-
@navigation_area ||= find_by_translatable(
105+
@set_navigation_area ||= find_by_translatable(
106106
translatable_type: ::BetterTogether::NavigationArea.name,
107107
friendly_id: params[:navigation_area_id]
108108
)

app/helpers/better_together/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def host_setup_wizard
7373
# This allows for cleaner calls to named routes without prefixing with 'better_together.'
7474
def method_missing(method, *args, &)
7575
if better_together_url_helper?(method)
76-
if args.any? and args.first.is_a? Hash
76+
if args.any? && args.first.is_a?(Hash)
7777
args = [args.first.merge(ApplicationController.default_url_options)]
7878
else
7979
args << ApplicationController.default_url_options

app/helpers/better_together/contact_details_helper.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
24
module ContactDetailsHelper
35
def render_contact_details(contactable, options = {})
@@ -23,7 +25,7 @@ def render_phone_numbers(contact_detail, options = {})
2325
phone_numbers = contact_detail.phone_numbers
2426
phone_numbers = phone_numbers.privacy_public unless include_private
2527

26-
return ''.html_safe if phone_numbers.size == 0
28+
return ''.html_safe if phone_numbers.empty?
2729

2830
render partial: 'better_together/phone_numbers/list', locals: { phone_numbers: phone_numbers }
2931
end
@@ -33,7 +35,7 @@ def render_email_addresses(contact_detail, options = {})
3335
email_addresses = contact_detail.email_addresses
3436
email_addresses = email_addresses.privacy_public unless include_private
3537

36-
return ''.html_safe if email_addresses.size == 0
38+
return ''.html_safe if email_addresses.empty?
3739

3840
render partial: 'better_together/email_addresses/list', locals: { email_addresses: email_addresses }
3941
end
@@ -43,7 +45,7 @@ def render_addresses(contact_detail, options = {})
4345
addresses = contact_detail.addresses
4446
addresses = addresses.privacy_public unless include_private
4547

46-
return ''.html_safe if addresses.size == 0
48+
return ''.html_safe if addresses.empty?
4749

4850
render partial: 'better_together/addresses/list', locals: { addresses: addresses }
4951
end
@@ -55,7 +57,7 @@ def render_social_media_accounts(contact_detail, options = {})
5557
social_media_accounts = contact_detail.social_media_accounts
5658
social_media_accounts = social_media_accounts.privacy_public unless include_private
5759

58-
return ''.html_safe if social_media_accounts.size == 0
60+
return ''.html_safe if social_media_accounts.empty?
5961

6062
render partial: 'better_together/social_media_accounts/list',
6163
locals: { social_media_accounts: social_media_accounts }
@@ -67,7 +69,7 @@ def render_host_community_social_media_accounts(include_private: false)
6769

6870
social_media_accounts = contact_detail.social_media_accounts.to_a
6971
social_media_accounts = social_media_accounts.select(&:privacy_public?) unless include_private
70-
return if social_media_accounts.size < 1
72+
return if social_media_accounts.empty?
7173

7274
render partial: 'better_together/social_media_accounts/navbar',
7375
locals: { social_media_accounts: social_media_accounts }
@@ -99,7 +101,7 @@ def render_website_links(contact_detail, options = {})
99101
website_links = contact_detail.website_links
100102
website_links = website_links.privacy_public unless include_private
101103

102-
return ''.html_safe if website_links.size == 0
104+
return ''.html_safe if website_links.empty?
103105

104106
render partial: 'better_together/website_links/list', locals: { website_links: website_links }
105107
end

0 commit comments

Comments
 (0)