Class: Puppet_X::Binford2k::Itemize::Runner
- Inherits:
-
Object
- Object
- Puppet_X::Binford2k::Itemize::Runner
- Defined in:
- lib/puppet_x/binford2k/itemize/runner.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #dump! ⇒ Object
- #expand(paths) ⇒ Object
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #run! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 7 def initialize( = {}) Puppet::Util::Log.newdestination(:console) @paths = (Array([:manifests])) @options = @results = {} if [:manifests].size == 1 root = [:manifests].first path = [File.("#{root}/metadata.json"), File.("#{root}/../metadata.json")].select { |p| File.exist? p }.first if path @metadata = JSON.parse(File.read(File.("#{path}/../metadata.json"))) @namespace = @metadata['name'].split(/[-\/]/).last # we can only use the module name part of this, not the user namespace @dependencies = @metadata['dependencies'].map do |dep| dep['name'].split(/[-\/]/).last end # inject a few mocked dependencies that we can assume will always exist @dependencies << @namespace @dependencies << 'puppet_enterprise' else # what error to display here? end end end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
6 7 8 |
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 6 def results @results end |
Instance Method Details
#dump! ⇒ Object
72 73 74 75 |
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 72 def dump! require 'json' puts JSON.pretty_generate(@results) end |
#expand(paths) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 36 def (paths) paths.map do |path| path = File.(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
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet_x/binford2k/itemize/runner.rb', line 50 def run! @paths.each do |path| Puppet.debug "Itemizing #{path}" parser = Puppet_X::Binford2k::Itemize::Parser.new(path, @options).parse! parser.results.each do |kind, counts| @results[kind] ||= {} counts.each do |name, count| segments = name.split('::') if @dependencies and segments.size > 1 Puppet.warn_once(:dependency, name, "Undeclared module dependancy: #{name}", :default, :default) unless @dependencies.include? segments.first end next if @options[:external] and segments.first == @namespace @results[kind][name] ||= 0 @results[kind][name] += count end end end self end |