Class: KafoModuleLint::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/kafo_module_lint/tasks.rb

Constant Summary collapse

DEFAULT_PATTERN =
'manifests/**/*.pp'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &task_block) ⇒ RakeTask

Returns a new instance of RakeTask.



13
14
15
16
17
18
# File 'lib/kafo_module_lint/tasks.rb', line 13

def initialize(*args, &task_block)
  @name = args.shift || :'lint:kafo_module'
  @pattern = DEFAULT_PATTERN
  @modulepath = File.join('spec', 'fixtures', 'modules')
  define(args, &task_block)
end

Instance Attribute Details

#modulepathObject

Returns the value of attribute modulepath.



11
12
13
# File 'lib/kafo_module_lint/tasks.rb', line 11

def modulepath
  @modulepath
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/kafo_module_lint/tasks.rb', line 9

def name
  @name
end

#patternObject

Returns the value of attribute pattern.



10
11
12
# File 'lib/kafo_module_lint/tasks.rb', line 10

def pattern
  @pattern
end

Instance Method Details

#define(args, &task_block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kafo_module_lint/tasks.rb', line 20

def define(args, &task_block)
  desc 'Lint Puppet module with KafoModuleLint'

  task_block.call(*[self, args].slice(0, task_block.arity)) if task_block

  Rake::Task[name].clear if Rake::Task.task_defined?(name)

  definition = Rake::Task.task_defined?('spec_prep') ? {name => [:'spec_prep']} : name
  task definition do
    RakeFileUtils.send(:verbose, true) do
      result = true
      TypeLoader.new(modulepath).with_types do
        FileList[pattern].each do |manifest|
          linter = Linter.new(manifest)
          result = false unless linter.pass?
          linter.puts_errors
        end
      end

      abort unless result
    end
  end

  Rake::Task[:lint].enhance [name] if Rake::Task.task_defined?('lint')
end