Class: StimulusAudit::AuditResult

Inherits:
Object
  • Object
show all
Defined in:
lib/stimulus_audit/auditor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defined_controllers:, used_controllers:, controller_locations:, usage_locations:) ⇒ AuditResult

Returns a new instance of AuditResult.



114
115
116
117
118
119
120
# File 'lib/stimulus_audit/auditor.rb', line 114

def initialize(defined_controllers:, used_controllers:,
               controller_locations:, usage_locations:)
  @defined_controllers = defined_controllers
  @used_controllers = used_controllers
  @controller_locations = controller_locations
  @usage_locations = usage_locations
end

Instance Attribute Details

#controller_locationsObject (readonly)

Returns the value of attribute controller_locations.



111
112
113
# File 'lib/stimulus_audit/auditor.rb', line 111

def controller_locations
  @controller_locations
end

#defined_controllersObject (readonly)

Returns the value of attribute defined_controllers.



111
112
113
# File 'lib/stimulus_audit/auditor.rb', line 111

def defined_controllers
  @defined_controllers
end

#usage_locationsObject (readonly)

Returns the value of attribute usage_locations.



111
112
113
# File 'lib/stimulus_audit/auditor.rb', line 111

def usage_locations
  @usage_locations
end

#used_controllersObject (readonly)

Returns the value of attribute used_controllers.



111
112
113
# File 'lib/stimulus_audit/auditor.rb', line 111

def used_controllers
  @used_controllers
end

Instance Method Details

#active_controllersObject



130
131
132
# File 'lib/stimulus_audit/auditor.rb', line 130

def active_controllers
  defined_controllers & used_controllers
end

#to_consoleObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/stimulus_audit/auditor.rb', line 134

def to_console
  puts "\nšŸ“Š Stimulus Controller Audit\n"

  if unused_controllers.any?
    puts "\nāŒ Defined but unused controllers:"
    unused_controllers.sort.each do |controller|
      puts "   #{controller}"
      puts "   └─ #{controller_locations[controller]}"
    end
  end

  if undefined_controllers.any?
    puts "\nāš ļø  Used but undefined controllers:"
    undefined_controllers.sort.each do |controller|
      puts "   #{controller}"
      usage_locations[controller].each do |file, lines|
        puts "   └─ #{file} (lines: #{lines.join(", ")})"
      end
    end
  end

  if active_controllers.any?
    puts "\nāœ… Active controllers:"
    active_controllers.sort.each do |controller|
      puts "   #{controller}"
      puts "   └─ Defined in: #{controller_locations[controller]}"
      puts "   └─ Used in:"
      usage_locations[controller].each do |file, lines|
        puts "      └─ #{file} (lines: #{lines.join(", ")})"
      end
    end
  end

  puts "\nšŸ“ˆ Summary:"
  puts "   Total controllers defined: #{defined_controllers.size}"
  puts "   Total controllers in use:  #{used_controllers.size}"
  puts "   Unused controllers:        #{unused_controllers.size}"
  puts "   Undefined controllers:     #{undefined_controllers.size}"
  puts "   Properly paired:           #{active_controllers.size}"
end

#undefined_controllersObject



126
127
128
# File 'lib/stimulus_audit/auditor.rb', line 126

def undefined_controllers
  used_controllers - defined_controllers
end

#unused_controllersObject



122
123
124
# File 'lib/stimulus_audit/auditor.rb', line 122

def unused_controllers
  defined_controllers - used_controllers
end