Class: ClassVacuum

Inherits:
Tool
  • Object
show all
Defined in:
lib/shed/class_vacuum.rb

Overview

This tool compares a mxmlc generated link-report against a manifest file created by the as-manifest tool to identify files that are in the project source tree but are no longer used by the application.

Before executing this script make sure the relevant link reports and manifest files have been generated.

Constant Summary

Constants inherited from Tool

Tool::INVALID_OPTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Tool

#add_sigint_handler, #generated_at, #log, #puts, #to_disk

Constructor Details

#initialize(opt, out = STDOUT) ⇒ ClassVacuum

Returns a new instance of ClassVacuum.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shed/class_vacuum.rb', line 16

def initialize(opt,out=STDOUT)
  super(opt,out)

  @link_report = opt[:link_report]
  @manifest = opt[:manifest]
  @link_regex = /<script name=".*\/(\w+)\.(as|mxml)/
  @manifest_regex = /<component id="(\w+)"/
  @empty_packages = []

  do_exit unless valid_opts

  detect

  @report = describe

  to_disk(@report)
end

Instance Attribute Details

#empty_packagesObject (readonly)

Returns the value of attribute empty_packages.



12
13
14
# File 'lib/shed/class_vacuum.rb', line 12

def empty_packages
  @empty_packages
end

#reportObject (readonly)

Returns the value of attribute report.



12
13
14
# File 'lib/shed/class_vacuum.rb', line 12

def report
  @report
end

#unused_classesObject (readonly)

Returns the value of attribute unused_classes.



12
13
14
# File 'lib/shed/class_vacuum.rb', line 12

def unused_classes
  @unused_classes
end

Instance Method Details

#detectObject

Scans the project and detects classes that are in the source tree that are not in the compiler manifest report.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/shed/class_vacuum.rb', line 45

def detect
  puts "Scanning project for classes that are uncompiled..."

  @manifest_classes = linked(@manifest, @manifest_regex, 'manifest')
  @link_classes = linked(@link_report, @link_regex, 'link-report')

  @unused_classes = @manifest_classes-@link_classes
  find_empties(@src)

  summarise
end

#valid_optsObject

Valid if a link report, manifest and source directory has been supplied.



37
38
39
# File 'lib/shed/class_vacuum.rb', line 37

def valid_opts
  File.exist?(@link_report) && File.exist?(@manifest) && File.exist?(@src) rescue false
end