Skip to content

Commit

Permalink
Apply Rubocop Performance/BlockGivenWithExplicitBlock (mastodon#23441)
Browse files Browse the repository at this point in the history
* Apply Rubocop Performance/BlockGivenWithExplicitBlock

* Unprefix used block parameter
  • Loading branch information
nschonni authored Feb 8, 2023
1 parent 26ac244 commit 0d1f192
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def omniauth_only?
def link_to_login(name = nil, html_options = nil, &block)
target = new_user_session_path

html_options = name if block_given?
html_options = name if block

if omniauth_only? && Devise.mappings[:user].omniauthable? && User.omniauth_providers.size == 1
target = omniauth_authorize_path(:user, User.omniauth_providers[0])
html_options ||= {}
html_options[:method] = :post
end

if block_given?
if block
link_to(target, html_options, &block)
else
link_to(name, target, html_options)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/jsonld_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def build_request(uri, on_behalf_of = nil)
end
end

def load_jsonld_context(url, _options = {}, &_block)
def load_jsonld_context(url, _options = {}, &block)
json = Rails.cache.fetch("jsonld:context:#{url}", expires_in: 30.days, raw: true) do
request = Request.new(:get, url)
request.add_headers('Accept' => 'application/ld+json')
Expand All @@ -226,6 +226,6 @@ def load_jsonld_context(url, _options = {}, &_block)

doc = JSON::LD::API::RemoteDocument.new(json, documentUrl: url)

block_given? ? yield(doc) : doc
block ? yield(doc) : doc
end
end
2 changes: 1 addition & 1 deletion app/lib/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def extract_entities_with_indices(text, options = {}, &block)
return [] if entities.empty?

entities = remove_overlapping_entities(entities)
entities.each(&block) if block_given?
entities.each(&block) if block
entities
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/trends/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def aggregate(date_range)
end

def each(&block)
if block_given?
if block
(0...7).map { |i| yield(get(i.days.ago)) }
else
to_enum(:each)
Expand Down

0 comments on commit 0d1f192

Please sign in to comment.