Module: Ra10ke::PuppetfileParser
- Included in:
- Deprecation::Validation, Duplicates::Verification, Validate::Validation
- Defined in:
- lib/ra10ke/puppetfile_parser.rb
Instance Method Summary collapse
-
#forge_modules(file = puppetfile) ⇒ Array
-
returns a array of hashes that contain modules from the Forge.
-
-
#git_modules(file = puppetfile) ⇒ Array
-
returns a array of hashes that contain modules with a git source.
-
-
#modules(puppetfile) ⇒ Array
[:name=>“stdlib”, :args=>[], :name=>“swap_file”, :args=>].
-
#parse_module_args(data) ⇒ Array
:name=>“stdlib”, :args=>[] :name=>“swap_file”, :args=>.
-
#process_args(args) ⇒ Array
[:name=>“razor”, :namespace=>“puppetlabs”, href="{:version=>"0.0.3"">args=>, :name=>“ntp”, :namespace=>“puppetlabs”}, :name=>“inifile”, :namespace=>“puppetlabs”, [{:git=>“github.com/nwops/reportslack.git”, :ref=>“1:ref=>“1.0:ref=>“1.0.20”], :name=>“reportslack”, :namespace=>“nwops”}, :args=>{:git=>“git://github.com/puppetlabs/puppetlabs-apt.git”, :name=>“apt”, :namespace=>nil} ].
Instance Method Details
#forge_modules(file = puppetfile) ⇒ Array
Returns - returns a array of hashes that contain modules from the Forge.
15 16 17 18 19 |
# File 'lib/ra10ke/puppetfile_parser.rb', line 15 def forge_modules(file = puppetfile) modules(file).reject do |mod| mod[:args].key?(:git) end end |
#git_modules(file = puppetfile) ⇒ Array
Returns - returns a array of hashes that contain modules with a git source.
8 9 10 11 12 |
# File 'lib/ra10ke/puppetfile_parser.rb', line 8 def git_modules(file = puppetfile) modules(file).find_all do |mod| mod[:args].key?(:git) end end |
#modules(puppetfile) ⇒ Array
[:name=>“stdlib”, :args=>[], :name=>“swap_file”, :args=>]
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ra10ke/puppetfile_parser.rb', line 26 def modules(puppetfile) @modules ||= begin return [] unless File.exist?(puppetfile) all_lines = File.read(puppetfile).lines.map(&:strip_comment) # remove comments from all the lines lines_without_comments = all_lines.reject { |line| line.match(/#.*\n/) || line.empty? }.join("\n") lines_without_comments.split(/^mod/).map do |line| next nil if /^forge/.match?(line) next nil if line.empty? parse_module_args(line) end.compact.uniq end end |
#parse_module_args(data) ⇒ Array
:name=>“stdlib”, :args=>[] :name=>“swap_file”, :args=>
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ra10ke/puppetfile_parser.rb', line 47 def parse_module_args(data) return {} if data.empty? args = data.split(',').map(&:strip) # we can't guarantee that there will be a namespace when git is used # remove quotes and dash and slash namespace, name = args.shift.gsub(/'|"/, '').split(%r{-|/}) name ||= namespace namespace = nil if namespace == name { namespace: namespace, name: name, args: process_args(args), } end |
#process_args(args) ⇒ Array
[:name=>“razor”, :namespace=>“puppetlabs”,
{:args=>[{:version=>"0.0.3"}], :name=>"ntp", :namespace=>"puppetlabs"},
{:args=>[], :name=>"inifile", :namespace=>"puppetlabs"},
{:args=>
[{:git=>"https://github.com/nwops/reportslack.git"}, {:ref=>"1.0.20"}],
:name=>"reportslack",
:namespace=>"nwops"},
{:args=>{:git=>"git://github.com/puppetlabs/puppetlabs-apt.git"},
:name=>"apt",
:namespace=>nil}
]
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ra10ke/puppetfile_parser.rb', line 77 def process_args(args) results = {} args.each do |arg| a = arg.gsub(/'|"/, '').split(/\A:|:\s|=>/).map(&:strip).reject(&:empty?) if a.count < 2 results[:version] = a.first else results[a.first.to_sym] = a.last end end results end |