Skip to content

Commit

Permalink
Use empty and present instead of checking size
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed Jan 21, 2024
1 parent c8e47b6 commit b3b4ff8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
12 changes: 1 addition & 11 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/hawk/http/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def instrument(type, payload)
elapsed = (Time.now.to_f - start) * 1000

url = payload[:url].to_s
if payload[:params] && payload[:params].size > 0
if payload[:params].present?
url << '?' << payload[:params].inject('') { |s, (k, v)| s << [k, '=', v, '&'].join }.chomp('&')
end

Expand Down
4 changes: 2 additions & 2 deletions lib/hawk/model/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.included(base)
#
def initialize(attributes = {}, params = {})
super
if attributes.size > 0 && self.class.associations?
if attributes.present? && self.class.associations?
preload_associations(attributes, params, self.class)
end
end
Expand Down Expand Up @@ -138,7 +138,7 @@ def associations
# Check whether associations are defined
#
def associations?
@_associations && @_associations.size > 0
@_associations.present?
end

# Check whether the given attribute is an association
Expand Down
2 changes: 1 addition & 1 deletion lib/hawk/model/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def method_missing(meth, *args, &block)

# If the method accepts a variable number of parameters, and
# the last provided one is an hash, merge the scoped params.
elsif method.arity < 0 && (method.arity + args.size == 0) && args.last.is_a?(Hash)
elsif method.arity < 0 && (method.arity + args.empty?) && args.last.is_a?(Hash)
args[-1] = params.deep_merge(args[-1])

end
Expand Down
2 changes: 1 addition & 1 deletion lib/hawk/model/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def cast!(attributes)
end

def schema(attributes = nil)
if attributes && attributes.size > 0 && self.class.schema.nil?
if attributes.present? && self.class.schema.nil?
self.class.define_schema_from(attributes)
end
self.class.schema || {}
Expand Down

0 comments on commit b3b4ff8

Please sign in to comment.