Class: AssetVacuum

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

Overview

This script scans all Actionscript classes and CSS files in a project to identify assets, like PNG files, that are in the project source tree but are no longer used by the application.

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) ⇒ AssetVacuum

Returns a new instance of AssetVacuum.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/shed/asset_vacuum.rb', line 13

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

  @src = opt[:src]
  @assets, @src_files, @declared, @unused = [], [], [], []

  do_exit unless valid_opts

  detect

  @report = describe

  to_disk(@report)
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



9
10
11
# File 'lib/shed/asset_vacuum.rb', line 9

def assets
  @assets
end

#declaredObject (readonly)

Returns the value of attribute declared.



9
10
11
# File 'lib/shed/asset_vacuum.rb', line 9

def declared
  @declared
end

#unusedObject (readonly)

Returns the value of attribute unused.



9
10
11
# File 'lib/shed/asset_vacuum.rb', line 9

def unused
  @unused
end

Instance Method Details

#detectObject

Scans the project and detects usage statitics for the assets it’s finds.



39
40
41
42
43
44
45
46
47
48
# File 'lib/shed/asset_vacuum.rb', line 39

def detect
  puts "Scanning project for assets that are unused..."

  scan_for_assets
  scan_for_declared

  @assets.each { |ass| @unused << ass unless is_asset_used(ass) }

  summarise
end

#valid_optsObject

Validates the given opts. Returns a boolean indicating if the src directory specified can be used.



32
33
34
# File 'lib/shed/asset_vacuum.rb', line 32

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