Skip to content

Commit

Permalink
Allow to deactivate inspection by component
Browse files Browse the repository at this point in the history
Based on #31 by @kamaradclimber
  • Loading branch information
gregkare committed Jan 6, 2015
1 parent f921e13 commit 74f25c9
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 24 deletions.
3 changes: 2 additions & 1 deletion knife-inspect.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'chef', chef_version
s.add_runtime_dependency 'yajl-ruby', '~> 1.2'
s.add_runtime_dependency 'parallel', '~> 1.3'
s.add_runtime_dependency 'parallel', '~> 1.3'
s.add_runtime_dependency 'inflecto', '~> 0.0.2'
end
26 changes: 17 additions & 9 deletions lib/chef/knife/inspect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,33 @@ class Inspect < Knife

banner 'knife inspect'

CHECKLISTS.map do |checklist|
opt_name = checklist.downcase.to_sym
option opt_name,
:long => "--[no-]#{opt_name}",
CHECKLISTS.each do |checklist|
checklist = HealthInspector::Checklists.const_get(checklist)

option checklist.option,
:long => "--[no-]#{checklist.option}",
:boolean => true,
:default => true,
:description => "Add or exclude #{opt_name} from inspection"
:description => "Add or exclude #{checklist.title} from inspection"
end

def run
results = CHECKLISTS.select do |checklist|
opt_name = checklist.downcase.to_sym
config[opt_name] or config[opt_name].nil?
end.map do |checklist|
results = checklists_to_run.map do |checklist|
HealthInspector::Checklists.const_get(checklist).run(self)
end

exit !results.include?(false)
end

private

def checklists_to_run
CHECKLISTS.select do |checklist|
checklist = HealthInspector::Checklists.const_get(checklist)

config[checklist.option]
end
end
end
end
end
19 changes: 15 additions & 4 deletions lib/health_inspector/checklists/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,35 @@
require 'pathname'
require 'yajl'
require 'parallel'
require 'inflecto'

module HealthInspector
module Checklists
class Base
include Color

class << self
attr_reader :title

def title(val = nil)
val.nil? ? @title : @title = val
def title
Inflecto.humanize(
Inflecto.underscore(
Inflecto.demodulize(self.to_s)
)
).downcase
end
end

def self.run(knife)
new(knife).run
end

def self.option
Inflecto.dasherize(
Inflecto.underscore(
Inflecto.demodulize(self.to_s)
)
).to_sym
end

def initialize(knife)
@context = Context.new(knife)
end
Expand Down
2 changes: 0 additions & 2 deletions lib/health_inspector/checklists/cookbooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ def checksum_cookbook_file(filepath)
end

class Cookbooks < Base
title 'cookbooks'

def load_item(name)
Cookbook.new(@context,
name: name,
Expand Down
2 changes: 0 additions & 2 deletions lib/health_inspector/checklists/data_bag_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class DataBagItem < Pairing
end

class DataBagItems < Base
title 'data bag items'

def load_item(name)
DataBagItem.new(@context,
name: name,
Expand Down
2 changes: 0 additions & 2 deletions lib/health_inspector/checklists/data_bags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class DataBag < Pairing
end

class DataBags < Base
title 'data bags'

def load_item(name)
DataBag.new(@context,
name: name,
Expand Down
2 changes: 0 additions & 2 deletions lib/health_inspector/checklists/environments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def validate_local_copy_exists
end

class Environments < Base
title 'environments'

def load_item(name)
Environment.new(@context,
name: name,
Expand Down
2 changes: 0 additions & 2 deletions lib/health_inspector/checklists/roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class Role < Pairing
end

class Roles < Base
title 'roles'

def load_item(name)
Role.new(@context,
name: name,
Expand Down

0 comments on commit 74f25c9

Please sign in to comment.