Class: AssetVacuum
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
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#declared ⇒ Object
readonly
Returns the value of attribute declared.
-
#unused ⇒ Object
readonly
Returns the value of attribute unused.
Instance Method Summary collapse
-
#detect ⇒ Object
Scans the project and detects usage statitics for the assets it’s finds.
-
#initialize(opt, out = STDOUT) ⇒ AssetVacuum
constructor
A new instance of AssetVacuum.
-
#valid_opts ⇒ Object
Validates the given opts.
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
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
9 10 11 |
# File 'lib/shed/asset_vacuum.rb', line 9 def assets @assets end |
#declared ⇒ Object (readonly)
Returns the value of attribute declared.
9 10 11 |
# File 'lib/shed/asset_vacuum.rb', line 9 def declared @declared end |
#unused ⇒ Object (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
#detect ⇒ Object
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_opts ⇒ Object
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 |