class Guard::Cookstyle

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/guard/cookstyle.rb, line 13
def initialize(options = {})
  super

  @options = {
    all_on_start: true,
    keep_failed:  true,
    notification: :failed,
    cli: nil,
    hide_stdout: false,
    cookbook_dirs: %w[.]
  }.merge(options)

  @failed_paths = []
end

Public Instance Methods

inspect_with_cookstyle(paths = []) click to toggle source
# File lib/guard/cookstyle.rb, line 47
def inspect_with_cookstyle(paths = [])
  runner = Runner.new(@options)
  passed = runner.run(paths)
  @failed_paths = runner.failed_paths
  throw :task_has_failed unless passed
rescue StandardError => error
  UI.error 'The following exception occurred while running guard-cookstyle: ' \
          "#{error.backtrace.first} #{error.message} (#{error.class.name})"
end
run_all() click to toggle source
# File lib/guard/cookstyle.rb, line 28
def run_all
  UI.info 'Inspecting Chef Cookbook style of all files'
  inspect_with_cookstyle
end
run_partially(paths) click to toggle source
# File lib/guard/cookstyle.rb, line 35
def run_partially(paths)
  paths += @failed_paths if @options[:keep_failed]
  paths = clean_paths(paths)

  return if paths.empty?

  displayed_paths = paths.map { |path| smart_path(path) }
  UI.info "Inspecting Chef Cookbook style: #{displayed_paths.join(' ')}"

  inspect_with_cookstyle(paths)
end