File tree Expand file tree Collapse file tree
health_inspector/checklists Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,5 +30,6 @@ Gem::Specification.new do |s|
3030
3131 s . add_runtime_dependency 'chef' , chef_version
3232 s . add_runtime_dependency 'yajl-ruby' , '~> 1.2'
33- s . add_runtime_dependency 'parallel' , '~> 1.3'
33+ s . add_runtime_dependency 'parallel' , '~> 1.3'
34+ s . add_runtime_dependency 'inflecto' , '~> 0.0.2'
3435end
Original file line number Diff line number Diff line change @@ -13,25 +13,33 @@ class Inspect < Knife
1313
1414 banner 'knife inspect'
1515
16- CHECKLISTS . map do |checklist |
17- opt_name = checklist . downcase . to_sym
18- option opt_name ,
19- :long => "--[no-]#{ opt_name } " ,
16+ CHECKLISTS . each do |checklist |
17+ checklist = HealthInspector ::Checklists . const_get ( checklist )
18+
19+ option checklist . option ,
20+ :long => "--[no-]#{ checklist . option } " ,
2021 :boolean => true ,
2122 :default => true ,
22- :description => "Add or exclude #{ opt_name } from inspection"
23+ :description => "Add or exclude #{ checklist . title } from inspection"
2324 end
2425
2526 def run
26- results = CHECKLISTS . select do |checklist |
27- opt_name = checklist . downcase . to_sym
28- config [ opt_name ] or config [ opt_name ] . nil?
29- end . map do |checklist |
27+ results = checklists_to_run . map do |checklist |
3028 HealthInspector ::Checklists . const_get ( checklist ) . run ( self )
3129 end
3230
3331 exit !results . include? ( false )
3432 end
33+
34+ private
35+
36+ def checklists_to_run
37+ CHECKLISTS . select do |checklist |
38+ checklist = HealthInspector ::Checklists . const_get ( checklist )
39+
40+ config [ checklist . option ]
41+ end
42+ end
3543 end
3644 end
3745end
Original file line number Diff line number Diff line change 22require 'pathname'
33require 'yajl'
44require 'parallel'
5+ require 'inflecto'
56
67module HealthInspector
78 module Checklists
89 class Base
910 include Color
1011
1112 class << self
12- attr_reader :title
13-
14- def title ( val = nil )
15- val . nil? ? @title : @title = val
13+ def title
14+ Inflecto . humanize ( underscored_class ) . downcase
1615 end
1716 end
1817
1918 def self . run ( knife )
2019 new ( knife ) . run
2120 end
2221
22+ def self . option
23+ Inflecto . dasherize ( underscored_class ) . to_sym
24+ end
25+
26+ def self . underscored_class
27+ Inflecto . underscore ( Inflecto . demodulize ( self . to_s ) )
28+ end
29+
2330 def initialize ( knife )
2431 @context = Context . new ( knife )
2532 end
Original file line number Diff line number Diff line change @@ -88,8 +88,6 @@ def checksum_cookbook_file(filepath)
8888 end
8989
9090 class Cookbooks < Base
91- title 'cookbooks'
92-
9391 def load_item ( name )
9492 Cookbook . new ( @context ,
9593 name : name ,
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ class DataBagItem < Pairing
99 end
1010
1111 class DataBagItems < Base
12- title 'data bag items'
13-
1412 def load_item ( name )
1513 DataBagItem . new ( @context ,
1614 name : name ,
Original file line number Diff line number Diff line change @@ -7,8 +7,6 @@ class DataBag < Pairing
77 end
88
99 class DataBags < Base
10- title 'data bags'
11-
1210 def load_item ( name )
1311 DataBag . new ( @context ,
1412 name : name ,
Original file line number Diff line number Diff line change @@ -15,8 +15,6 @@ def validate_local_copy_exists
1515 end
1616
1717 class Environments < Base
18- title 'environments'
19-
2018 def load_item ( name )
2119 Environment . new ( @context ,
2220 name : name ,
Original file line number Diff line number Diff line change @@ -8,8 +8,6 @@ class Role < Pairing
88 end
99
1010 class Roles < Base
11- title 'roles'
12-
1311 def load_item ( name )
1412 Role . new ( @context ,
1513 name : name ,
Original file line number Diff line number Diff line change 1515 knife_inspect . run
1616 end
1717
18+ before do
19+ # FIXME: Default config does not appear to be used by Chef 11
20+ described_class ::CHECKLISTS . each do |checklist |
21+ checklist = HealthInspector ::Checklists . const_get ( checklist )
22+
23+ knife_inspect . config [ checklist . option ] = true
24+ end
25+ end
26+
1827 context 'when all the checklists pass' do
1928 it 'runs all the check lists and exits with 0' do
2029 { HealthInspector ::Checklists ::Cookbooks => true ,
You can’t perform that action at this time.
0 commit comments