Skip to content

Commit 25ca7bd

Browse files
jcoynethatbudakguy
authored andcommitted
Prefer if x.blank? over unless x.present?
1 parent 504702c commit 25ca7bd

File tree

10 files changed

+10
-25
lines changed

10 files changed

+10
-25
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,6 @@ Rails/ApplicationMailer:
339339
Rails/ApplicationRecord:
340340
Enabled: false
341341

342-
# Offense count: 10
343-
# This cop supports unsafe autocorrection (--autocorrect-all).
344-
# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent.
345-
Rails/Blank:
346-
Exclude:
347-
- 'app/controllers/spotlight/exhibits_controller.rb'
348-
- 'app/helpers/spotlight/application_helper.rb'
349-
- 'app/jobs/spotlight/add_uploads_from_csv.rb'
350-
- 'app/models/spotlight/featured_image.rb'
351-
- 'app/models/spotlight/page.rb'
352-
- 'app/models/spotlight/resources/iiif_manifest.rb'
353-
- 'app/models/spotlight/resources/iiif_service.rb'
354-
- 'lib/migration/iiif.rb'
355-
- 'spec/support/features/test_features_helpers.rb'
356-
357342
# Offense count: 4
358343
# This cop supports unsafe autocorrection (--autocorrect-all).
359344
Rails/CompactBlank:

app/controllers/spotlight/exhibits_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def import_exhibit_params
115115
end
116116

117117
def build_initial_exhibit_contact_emails
118-
@exhibit.contact_emails.build unless @exhibit.contact_emails.present?
118+
@exhibit.contact_emails.build if @exhibit.contact_emails.blank?
119119
end
120120
end
121121
end

app/helpers/spotlight/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def render_document_class(document = @document)
9797
# Return a copy of the blacklight configuration
9898
# that only includes views conifgured by our block
9999
def blacklight_view_config_for_search_block(block)
100-
return {} unless block.view.present?
100+
return {} if block.view.blank?
101101

102102
# Reject any views that aren't configured to display for this block
103103
blacklight_config.view.select do |view, _|

app/jobs/spotlight/add_uploads_from_csv.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def resources(csv_data, exhibit)
4040

4141
encoded_csv(csv_data).each do |row|
4242
url = row.delete('url')
43-
next unless url.present?
43+
next if url.blank?
4444

4545
resource = Spotlight::Resources::Upload.new(
4646
data: row,

app/models/spotlight/featured_image.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FeaturedImage < ActiveRecord::Base
3636
attr_accessor :upload_id
3737

3838
def iiif_url
39-
return unless iiif_service_base.present?
39+
return if iiif_service_base.blank?
4040

4141
[iiif_service_base, iiif_region || 'full', image_size.join(','), '0', 'default.jpg'].join('/')
4242
end

app/models/spotlight/page.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def should_display_title?
129129
end
130130

131131
def lock!(user)
132-
create_lock(by: user).tap(&:current_session!) unless lock.present?
132+
create_lock(by: user).tap(&:current_session!) if lock.blank?
133133
end
134134

135135
def updated_after?(other_page)

app/models/spotlight/resources/iiif_manifest.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def add_metadata
8989

9090
def manifest_metadata
9191
metadata = metadata_class.new(manifest).to_solr
92-
return {} unless metadata.present?
92+
return {} if metadata.blank?
9393

9494
create_sidecars_for(*metadata.keys)
9595

@@ -203,7 +203,7 @@ def metadata
203203
end
204204

205205
def metadata_hash
206-
return {} unless metadata.present?
206+
return {} if metadata.blank?
207207
return {} unless metadata.is_a?(Array)
208208

209209
metadata.each_with_object({}) do |md, hash|

app/models/spotlight/resources/iiif_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def recursive_manifests(thing, &block)
6161

6262
thing.manifests.each(&block)
6363

64-
return unless thing.collections.present?
64+
return if thing.collections.blank?
6565

6666
thing.collections.each do |collection|
6767
recursive_manifests(collection, &block)

lib/migration/iiif.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def update_iiif_url(image)
9797
end
9898

9999
def coordinates(image)
100-
return unless image.image_crop_x.present?
100+
return if image.image_crop_x.blank?
101101

102102
[image.image_crop_x, image.image_crop_y, image.image_crop_w, image.image_crop_h].join(',')
103103
end

spec/support/features/test_features_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def add_widget(type)
4646
end
4747

4848
def click_add_widget
49-
unless all('.st-block-replacer').present?
49+
if all('.st-block-replacer').blank?
5050
expect(page).to have_css('.st-block-addition')
5151
first('.st-block-addition').click
5252
end

0 commit comments

Comments
 (0)