Class: Juicer::Command::List
- Inherits:
-
CmdParse::Command
- Object
- CmdParse::Command
- Juicer::Command::List
- Includes:
- Util
- Defined in:
- lib/juicer/command/list.rb
Overview
Displays a list of files that make up the dependency chain for the input files/patterns.
Instance Method Summary collapse
-
#execute(args) ⇒ Object
Execute command.
-
#initialize(log = nil) ⇒ List
constructor
Initializes command.
Methods included from Util
Constructor Details
#initialize(log = nil) ⇒ List
Initializes command
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/juicer/command/list.rb', line 15 def initialize(log = nil) super('list', false, true) @log = log self.short_desc = "Lists all dependencies for all input files/patterns" self.description = <<-EOF Dependencies are looked up recursively. The dependency chain reveals which files will be joined by juicer merge. Input parameters may be: * Single file, ie $ juicer list myfile.css * Single glob pattern, ie $ juicer list **/*.css * Multiple mixed arguments, ie $ juicer list **/*.js **/*.css EOF end |
Instance Method Details
#execute(args) ⇒ Object
Execute command
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/juicer/command/list.rb', line 32 def execute(args) if args.length == 0 raise ArgumentError.new('Please provide atleast one input file/pattern') end types = { :js => Juicer::JavaScriptDependencyResolver.new, :css => Juicer::CssDependencyResolver.new } result = files(args).map { |file| type = file.split(".").pop.to_sym raise FileNotFoundError.new("Unable to guess type (CSS/JavaScript) of file #{relative(file)}") unless types[type] deps = relative types[type].resolve(file) # there may only be one dependency, which resolve() returns as a string deps = deps.join("\n ") if deps.is_a? Array "Dependency chain for #{relative file}:\n #{deps}" }.join("\n\n") + "\n" @log.info result result end |