2015-08-13 03:47:02 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
module Vulcano::Targets
|
|
|
|
module DirsHelper
|
|
|
|
class ChefAuditDir
|
|
|
|
def handles?(paths)
|
|
|
|
paths.include?('recipes') and paths.include?('metadata.rb')
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_filenames(paths)
|
|
|
|
paths.find_all do |x|
|
|
|
|
x.start_with? 'recipes/' and x.end_with? '.rb'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ServerspecDir
|
|
|
|
def handles?(paths)
|
|
|
|
paths.include?('spec')
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_filenames(paths)
|
|
|
|
paths.find_all do |path|
|
|
|
|
path.start_with? 'spec' and path.end_with? '_spec.rb'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class FlatDir
|
|
|
|
def handles?(paths)
|
|
|
|
get_filenames(paths).empty? == false
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_filenames(paths)
|
2015-09-05 14:07:54 +00:00
|
|
|
paths.find_all { |x| x.end_with?('.rb') and !x.include?('/') }
|
2015-08-13 03:47:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
HANDLERS = [
|
|
|
|
ChefAuditDir, ServerspecDir, FlatDir
|
2015-09-09 10:18:42 +00:00
|
|
|
].map(&:new)
|
2015-08-13 03:47:02 +00:00
|
|
|
|
2015-09-09 10:18:42 +00:00
|
|
|
def self.get_handler(paths)
|
2015-09-05 14:07:54 +00:00
|
|
|
HANDLERS.find { |x| x.handles? paths }
|
2015-08-13 03:47:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|