Skip to content

Commit

Permalink
Style/GuardClause-20221108233723 (#104)
Browse files Browse the repository at this point in the history
* 🚓 regenerate rubocop todo

* 🚓 Style/GuardClause

* 🚓 regenerate rubocop todo

---------

Co-authored-by: Rubocop Challenger <rubocop@payrollhero.com>
Co-authored-by: Mathieu Jobin <99191+mathieujobin@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 31, 2023
1 parent 4f412bd commit 3b30cc0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
8 changes: 0 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ Style/Documentation:
- 'lib/webhook_system/encoder.rb'
- 'lib/webhook_system/subscription_topic.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
Exclude:
- 'lib/webhook_system/base_event.rb'
- 'lib/webhook_system/job.rb'

# Offense count: 19
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
Expand Down
9 changes: 5 additions & 4 deletions lib/webhook_system/base_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ def with_caller_backtrace(exception, backtrack = 2)
end

def validate_attribute_name(key)
if self.class.key_is_reserved?(key)
message = "#{self.class.name} should not be defining an attribute named #{key} since its reserved"
raise ArgumentError, message
end
return unless self.class.key_is_reserved?(key)

message = "#{self.class.name} should not be defining an attribute named #{key} since its reserved"
raise ArgumentError, message

end

def each_attribute(&block)
Expand Down
19 changes: 10 additions & 9 deletions lib/webhook_system/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ def self.post(subscription, event)
def self.ensure_success(response, http_method, subscription)
url = subscription.url
status = response.status
unless (200..299).cover? status
if subscription.respond_to?(:account_id)
account_info = subscription.account_info
inner = "failed for account #{account_info} with"
else
inner = "failed with"
end
text = "#{http_method} request to #{url} #{inner} code: #{status} and error #{response.body}"
raise RequestFailed.new(text, status, response.body)
return if (200..299).cover? status

if subscription.respond_to?(:account_id)
account_info = subscription.account_info
inner = "failed for account #{account_info} with"
else
inner = "failed with"
end
text = "#{http_method} request to #{url} #{inner} code: #{status} and error #{response.body}"
raise RequestFailed.new(text, status, response.body)

end

def self.build_request(client, subscription, event)
Expand Down

0 comments on commit 3b30cc0

Please sign in to comment.