diff --git a/lib/terraspace/compiler/builder.rb b/lib/terraspace/compiler/builder.rb index a9610913..7d350419 100644 --- a/lib/terraspace/compiler/builder.rb +++ b/lib/terraspace/compiler/builder.rb @@ -72,13 +72,7 @@ def with_path(path) end def skip?(src_path) - return true unless File.file?(src_path) - # certain folders will be skipped - src_path.include?("#{@mod.root}/config/args") || - src_path.include?("#{@mod.root}/config/helpers") || - src_path.include?("#{@mod.root}/config/hooks") || - src_path.include?("#{@mod.root}/test") || - src_path.include?("#{@mod.root}/tfvars") + Skip.new(@mod, src_path).check? end def search(expr) diff --git a/lib/terraspace/compiler/builder/skip.rb b/lib/terraspace/compiler/builder/skip.rb new file mode 100644 index 00000000..c45e81ad --- /dev/null +++ b/lib/terraspace/compiler/builder/skip.rb @@ -0,0 +1,28 @@ +class Terraspace::Compiler::Builder + class Skip + def initialize(mod, src_path) + @mod, @src_path = mod, src_path + end + + def check? + return true unless File.file?(@src_path) + + # skip certain folders + check_dirs?( + "config/args", + "config/helpers", + "config/hooks", + "test", + "tfvars", + ) + end + + def check_dirs?(*names) + names.flatten.detect { |name| check_dir?(name) } + end + + def check_dir?(name) + @src_path.include?("#{@mod.root}/#{name}/") + end + end +end