Skip to content

Commit beaf50e

Browse files
committed
Rubocop fixes
1 parent a6c9b01 commit beaf50e

33 files changed

+122
-80
lines changed

app/controllers/better_together/uploads_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
module BetterTogether
4+
# CRUD for Uploads
45
class UploadsController < FriendlyResourceController
56
before_action :set_resource_instance, only: %i[show edit update destroy download]
67
before_action :authorize_resource, only: %i[new show edit update destroy download]

app/helpers/better_together/contact_details_helper.rb

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
module BetterTogether
44
module ContactDetailsHelper # rubocop:todo Style/Documentation
5-
def render_contact_details(contactable, options = {})
5+
# rubocop:todo Metrics/MethodLength
6+
def render_contact_details(contactable, options = {}) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
67
# Options
78
include_private = options.fetch(:include_private, false)
89

@@ -23,6 +24,7 @@ def render_contact_details(contactable, options = {})
2324
content << render_addresses(contact_detail, include_private:)
2425
content
2526
end
27+
# rubocop:enable Metrics/MethodLength
2628

2729
def render_contacts(contactable, options = {})
2830
# Options
@@ -34,25 +36,31 @@ def render_contacts(contactable, options = {})
3436

3537
# Render partials for each contact type
3638
content = contacts.map do |contact|
37-
content_tag(:div, class: 'contact mb-3 col') do
38-
name_and_role = content_tag(:div, class: 'name-and-role mb-3') do
39-
name = contact.name.present? ? content_tag(:strong, contact.name) : ''.html_safe
40-
role = contact.role.present? ? ", #{content_tag(:strong, contact.role)}".html_safe : ''.html_safe
41-
name + role
42-
end
43-
44-
name_and_role +
45-
render_social_media_accounts(contact, include_private:) +
46-
render_website_links(contact, include_private:) +
47-
render_phone_numbers(contact, include_private:) +
48-
render_email_addresses(contact, include_private:) +
49-
render_addresses(contact, include_private:)
50-
end
39+
render_contact(contact, include_private:)
5140
end
5241

5342
safe_join(content)
5443
end
5544

45+
# rubocop:todo Metrics/MethodLength
46+
def render_contact(contact, include_private) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
47+
content_tag(:div, class: 'contact mb-3 col') do
48+
name_and_role = content_tag(:div, class: 'name-and-role mb-3') do
49+
name = contact.name.present? ? content_tag(:strong, contact.name) : ''.html_safe
50+
role = contact.role.present? ? ", #{content_tag(:strong, contact.role)}".html_safe : ''.html_safe
51+
name + role
52+
end
53+
54+
name_and_role +
55+
render_social_media_accounts(contact, include_private:) +
56+
render_website_links(contact, include_private:) +
57+
render_phone_numbers(contact, include_private:) +
58+
render_email_addresses(contact, include_private:) +
59+
render_addresses(contact, include_private:)
60+
end
61+
end
62+
# rubocop:enable Metrics/MethodLength
63+
5664
def render_phone_numbers(contact_detail, options = {})
5765
include_private = options.fetch(:include_private, false)
5866
phone_numbers = contact_detail.phone_numbers
@@ -109,25 +117,18 @@ def render_host_community_social_media_accounts(include_private: false)
109117
end
110118

111119
# rubocop:todo Metrics/MethodLength
112-
def social_media_icon_class(platform) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength
113-
case platform
114-
when 'Facebook'
115-
'fab fa-facebook-f'
116-
when 'Instagram'
117-
'fab fa-instagram'
118-
when 'Bluesky'
119-
'fab fa-bluesky'
120-
when 'LinkedIn'
121-
'fab fa-linkedin-in'
122-
when 'YouTube'
123-
'fab fa-youtube'
124-
when 'TikTok'
125-
'fab fa-tiktok'
126-
when 'Reddit'
127-
'fab fa-reddit-alien'
128-
when 'WhatsApp'
129-
'fab fa-whatsapp'
130-
end
120+
def social_media_icon_class(platform)
121+
icon_classes = {
122+
'Facebook' => 'fab fa-facebook-f',
123+
'Instagram' => 'fab fa-instagram',
124+
'Bluesky' => 'fab fa-bluesky',
125+
'LinkedIn' => 'fab fa-linkedin-in',
126+
'YouTube' => 'fab fa-youtube',
127+
'TikTok' => 'fab fa-tiktok',
128+
'Reddit' => 'fab fa-reddit-alien',
129+
'WhatsApp' => 'fab fa-whatsapp'
130+
}
131+
icon_classes[platform]
131132
end
132133
# rubocop:enable Metrics/MethodLength
133134

app/helpers/better_together/human_attribute_name_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
module BetterTogether
4+
# Helps format human attribute names for models
45
module HumanAttributeNameHelper
56
# Dispatches the human attribute name for a given model instance and attribute
67
# @param model [ActiveRecord::Base] The model instance

app/helpers/better_together/image_helper.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,30 @@ def profile_image_tag(entity, options = {}) # rubocop:todo Metrics/MethodLength,
7676
# rubocop:enable Metrics/CyclomaticComplexity
7777
# rubocop:enable Metrics/PerceivedComplexity
7878

79-
def render_image_gallery(images, venue_name)
79+
def render_image_gallery(images, name)
8080
return if images.blank?
8181

8282
content_tag(:section, class: 'image-gallery mb-4', data: { controller: 'better_together--masonry' }) do
8383
content_tag(:div, class: 'row g-3') do
84-
if images.size == 1
85-
# Render a single image
86-
content_tag(:div, class: 'col col-12') do
87-
image_tag(images.first.media, alt: venue_name, class: 'img-fluid rounded mb-3')
88-
end
89-
else
90-
# Render a gallery for multiple images
91-
images.map.with_index do |image, _index|
92-
content_tag(:div, class: 'col align-content-center col-md-4') do
93-
image_tag(image.media, alt: venue_name, class: 'img-fluid rounded')
94-
end
95-
end.join.html_safe
96-
end
84+
images.size == 1 ? render_single_image(images.first, name) : render_image_grid(images, name)
9785
end
9886
end
9987
end
10088

89+
def render_single_image(image, name)
90+
content_tag(:div, class: 'col col-12') do
91+
image_tag(image.media, alt: name, class: 'img-fluid rounded mb-3')
92+
end
93+
end
94+
95+
def render_image_grid(images, name)
96+
images.map do |image|
97+
content_tag(:div, class: 'col align-content-center col-md-4') do
98+
image_tag(image.media, alt: name, class: 'img-fluid rounded')
99+
end
100+
end.join.html_safe
101+
end
102+
101103
private
102104

103105
def default_cover_image(entity, image_format)

app/helpers/better_together/sidebar_nav_helper.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ def render_nav_item(nav_item:, current_page:, level:, parent_id:, index:) # rubo
6363
end
6464

6565
if has_children
66-
header_content += link_to "#toggle-#{collapse_id}", class: "sidebar-level-toggle #{link_classes}", 'data-bs-toggle': 'collapse',
67-
# rubocop:todo Layout/LineLength
68-
'data-bs-target': "##{collapse_id}", 'aria-expanded': expanded_state, 'aria-controls': collapse_id do
69-
# rubocop:enable Layout/LineLength
66+
header_content += link_to "#toggle-#{collapse_id}",
67+
class: "sidebar-level-toggle #{link_classes}",
68+
'data-bs-toggle': 'collapse',
69+
'data-bs-target': "##{collapse_id}",
70+
'aria-expanded': expanded_state,
71+
'aria-controls': collapse_id do
7072
'<i class="fas me-2"></i>'.html_safe
7173
end
7274
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
module BetterTogether
4-
module FilesHelper
4+
# helper methods for file uploads
5+
module UploadsHelper
56
end
67
end

app/models/better_together/address.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ def self.address_formats
2626
}
2727
end
2828

29+
def self.permitted_attributes(id: false, destroy: false)
30+
super + %i[
31+
physical postal line1 line2 city_name state_province_name
32+
postal_code country_name
33+
]
34+
end
35+
2936
def to_formatted_s(
3037
included: %i[line1 line2 city_name state_province_name postal_code country_name],
3138
excluded: [],
3239
format: nil
3340
)
34-
if self.class.address_formats[format]
35-
address_format = self.class.address_formats[format]
36-
format_included = address_format[:included]
37-
format_excluded = address_format[:excluded]
38-
39-
included = format_included if format_included.present?
40-
excluded = format_excluded if format_excluded.present?
41-
end
41+
included, excluded = resolve_format(format, included, excluded)
4242

4343
attrs = included - excluded
44-
attrs.map { |attr| public_send attr }
44+
attrs.map { |attr| public_send(attr) }
4545
.select(&:present?).join(', ')
4646
end
4747

@@ -51,17 +51,23 @@ def to_s
5151

5252
protected
5353

54-
def self.permitted_attributes(id: false, destroy: false)
55-
super + %i[
56-
physical postal line1 line2 city_name state_province_name
57-
postal_code country_name
58-
]
59-
end
60-
6154
def at_least_one_address_type
6255
return if physical || postal
6356

6457
errors.add(:base, 'Address must be either physical, postal, or both')
6558
end
59+
60+
def resolve_format(format, included, excluded)
61+
return [included, excluded] unless self.class.address_formats[format]
62+
63+
address_format = self.class.address_formats[format]
64+
format_included = address_format[:included]
65+
format_excluded = address_format[:excluded]
66+
67+
included = format_included if format_included.present?
68+
excluded = format_excluded if format_excluded.present?
69+
70+
[included, excluded]
71+
end
6672
end
6773
end

app/models/better_together/application_record.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def cache_key
2424
end
2525

2626
def to_s
27-
return name if respond_to?(:name) && name.present?
28-
return title if respond_to?(:title) && title.present?
29-
return identifier if respond_to?(:identifier) && identifier.present?
30-
return slug if respond_to?(:slug) && slug.present?
27+
attributes = %i[name title identifier slug]
28+
attributes.each do |attr|
29+
return public_send(attr) if respond_to?(attr) && public_send(attr).present?
30+
end
3131

3232
super
3333
end

app/models/better_together/contact_detail.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ContactDetail < ApplicationRecord # rubocop:todo Style/Documentation
1515
allow_destroy: true,
1616
reject_if: :all_blank
1717

18-
def self.permitted_attributes(id: false, destroy: false, exclude_extra: false)
18+
def self.permitted_attributes(id: false, destroy: false, exclude_extra: false) # rubocop:todo Metrics/MethodLength
1919
[
2020
:name, :role,
2121
{

app/models/better_together/geography/geospatial_space.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module BetterTogether
44
module Geography
5+
# Join record between a polymorphic geospatial record and a Space
56
class GeospatialSpace < ApplicationRecord
67
include Positioned
78
include PrimaryFlag

0 commit comments

Comments
 (0)