Class: Puppet_X::Binford2k::Itemize::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/binford2k/itemize/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



3
4
5
6
7
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 3

def initialize(options = {})
  @paths   = expand(Array(options[:manifests]))
  @options = options
  @results = {}
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



2
3
4
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 2

def results
  @results
end

Instance Method Details

#dump!Object



38
39
40
41
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 38

def dump!
  require 'json'
  puts JSON.pretty_generate(@results)
end

#expand(paths) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 9

def expand(paths)
  paths.map do |path|
    path = File.expand_path(path)

    if File.file? path
      path
    elsif File.directory? path
      Dir.glob("#{path}/**/*.pp")
    else
      raise "Path '#{path}' doesn't appear to be a file or directory"
    end
  end.flatten
end

#run!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 23

def run!
  @paths.each do |path|
    parser = Puppet_X::Binford2k::Itemize::Parser.new(path, @options).parse!
    parser.results.each do |kind, counts|
      @results[kind] ||= {}

      counts.each do |name, count|
        @results[kind][name] ||= 0
        @results[kind][name]  += count
      end
    end
  end
  self
end