Class: Juicer::Command::Verify

Inherits:
CmdParse::Command
  • Object
show all
Includes:
Util
Defined in:
lib/juicer/command/verify.rb

Overview

Verifies problem-free-ness of source code (JavaScript and CSS)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#files, #relative

Constructor Details

#initialize(log = nil) ⇒ Verify

Initializes command



15
16
17
18
19
20
21
22
23
24
# File 'lib/juicer/command/verify.rb', line 15

def initialize(log = nil)
  super('verify', false, true)
  @log = log || Logger.new($STDIO)
  self.short_desc = "Verifies that the given JavaScript/CSS file is problem free"
  self.description = <<-EOF
Uses JsLint (http://www.jslint.com) to check that code adheres to good coding
practices to avoid potential bugs, and protect against introducing bugs by
minifying.
  EOF
end

Class Method Details

.check_all(files, log = nil) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/juicer/command/verify.rb', line 34

def self.check_all(files, log = nil)
  log ||= Logger.new($stdio)
  jslint = Juicer::JsLint.new(:bin_path => Juicer.home)
  problems = false

  # Check that JsLint is installed
  raise FileNotFoundError.new("Missing 3rd party library JsLint, install with\njuicer install jslint") if jslint.locate_lib.nil?

  # Verify all files
  files.each do |file|
    log.info "Verifying #{file} with JsLint"
    report = jslint.check(file)

    if report.ok?
      log.info "  OK!"
    else
      problems = true
      log.warn "  Problems detected"
      log.warn "  #{report.errors.join("\n").gsub(/\n/, "\n  ")}\n"
    end
  end

  !problems
end

Instance Method Details

#execute(args) ⇒ Object

Execute command

Raises:

  • (ArgumentError)


28
29
30
31
32
# File 'lib/juicer/command/verify.rb', line 28

def execute(args)
  # Need atleast one file
  raise ArgumentError.new('Please provide atleast one input file/pattern') if args.length == 0
  Juicer::Command::Verify.check_all(files(args), @log)
end