Class: Chatwerk::Views::ViolationsListView

Inherits:
BaseView
  • Object
show all
Defined in:
lib/chatwerk/views/violations_list_view.rb

Instance Attribute Summary

Attributes inherited from BaseView

#data, #output

Instance Method Summary collapse

Methods inherited from BaseView

#initialize, render, #render

Constructor Details

This class inherits a constructor from Chatwerk::Views::BaseView

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chatwerk::Views::BaseView

Instance Method Details

#template(package:, violations:) ⇒ Object

The anonymous_source_counts method returns a hash as follows: { "::Core::User" => { "User.find()" => 2, "User.create()" => 1 } "::Core::Product" => { "Product.find()" => 1, "Product.create()" => 1 } }



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chatwerk/views/violations_list_view.rb', line 17

def template(package:, violations:)
  sums = violations.anonymous_source_counts.transform_values do |source_counts|
    source_counts.values.sum
  end

  if sums.empty?
    NoViolationsView.render(package:)
  else
    sums.sort_by { |_, count| -count }.map do |constant_name, count|
      "#{constant_name} (#{format_count(count, 'violation')})\n"
    end.join
  end
end