ManageIQ/ovirt

View on GitHub
examples/event_monitor_example.rb

Summary

Maintainability
A
0 mins
Test Coverage

Use sort_by(&:to_s) instead of sort { |a, b| a.to_s <=> b.to_s }.
Open

  base.keys.sort { |a, b| a.to_s <=> b.to_s }.each do |key|
Severity: Minor
Found in examples/event_monitor_example.rb by rubocop

This cop identifies places where sort { |a, b| a.foo <=> b.foo } can be replaced by sort_by(&:foo). This cop also checks max and min methods.

Example:

# bad
array.sort { |a, b| a.foo <=> b.foo }
array.max { |a, b| a.foo <=> b.foo }
array.min { |a, b| a.foo <=> b.foo }
array.sort { |a, b| a[:foo] <=> b[:foo] }

# good
array.sort_by(&:foo)
array.sort_by { |v| v.foo }
array.sort_by do |var|
  var.foo
end
array.max_by(&:foo)
array.min_by(&:foo)
array.sort_by { |a| a[:foo] }

Use sort_by(&:to_s) instead of sort { |a, b| a.to_s <=> b.to_s }.
Open

    base.relationships.keys.sort { |a, b| a.to_s <=> b.to_s }.each do |rel|
Severity: Minor
Found in examples/event_monitor_example.rb by rubocop

This cop identifies places where sort { |a, b| a.foo <=> b.foo } can be replaced by sort_by(&:foo). This cop also checks max and min methods.

Example:

# bad
array.sort { |a, b| a.foo <=> b.foo }
array.max { |a, b| a.foo <=> b.foo }
array.min { |a, b| a.foo <=> b.foo }
array.sort { |a, b| a[:foo] <=> b[:foo] }

# good
array.sort_by(&:foo)
array.sort_by { |v| v.foo }
array.sort_by do |var|
  var.foo
end
array.max_by(&:foo)
array.min_by(&:foo)
array.sort_by { |a| a[:foo] }

There are no issues that match your filters.

Category
Status