Skip to content

Commit

Permalink
Merge pull request #190 from juniorsysadmin/fix-rubocop
Browse files Browse the repository at this point in the history
WIP: Attempt to fix failng Rubocop lint checks
  • Loading branch information
igalic committed Jan 7, 2016
2 parents c1b9ca8 + 0b60129 commit cf06a87
Show file tree
Hide file tree
Showing 10 changed files with 969 additions and 1,110 deletions.
20 changes: 10 additions & 10 deletions lib/puppet/provider/package/npm.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
require 'puppet/provider/package'

Puppet::Type.type(:package).provide :npm, :parent => Puppet::Provider::Package do
desc "npm is the package manager for Node.js. This provider only handles global packages."
desc 'npm is the package manager for Node.js. This provider only handles global packages.'

has_feature :versionable

if Puppet::Util::Package.versioncmp(Puppet.version, '3.0') >= 0
has_command(:npm, 'npm') do
is_optional
environment :HOME => "/root"
environment :HOME => '/root'
end
else
optional_commands :npm => 'npm'
end

def self.npmlist
# Ignore non-zero exit codes as they can be minor, just try and parse JSON
output = execute([command(:npm), 'list', '--json', '--global'], {:combine => false})
output = execute([command(:npm), 'list', '--json', '--global'], :combine => false)
Puppet.debug("Warning: npm list --json exited with code #{$CHILD_STATUS.exitstatus}") unless $CHILD_STATUS.success?
begin
# ignore any npm output lines to be a bit more robust
output = PSON.parse(output.lines.select{ |l| l =~ /^((?!^npm).*)$/}.join("\n"), {:max_nesting => 100} )
output = PSON.parse(output.lines.select { |l| l =~ /^((?!^npm).*)$/ }.join("\n"), :max_nesting => 100)
@npmlist = output['dependencies'] || {}
rescue PSON::ParserError => e
Puppet.debug("Error: npm list --json command error #{e.message}")
Expand All @@ -34,15 +34,15 @@ def npmlist

def self.instances
@npmlist ||= npmlist
@npmlist.collect do |k,v|
new({:name=>k, :ensure=>v['version'], :provider=>'npm'})
@npmlist.collect do |k, v|
new(:name => k, :ensure => v['version'], :provider => 'npm')
end
end

def query
list = npmlist

if list.has_key?(resource[:name]) and list[resource[:name]].has_key?('version')
if list.key?(resource[:name]) && list[resource[:name]].key?('version')
version = list[resource[:name]]['version']
{ :ensure => version, :name => resource[:name] }
else
Expand All @@ -51,16 +51,16 @@ def query
end

def latest
if /#{resource[:name]}@([\d\.]+)/ =~ npm('outdated', '--global', resource[:name])
@latest = $1
if /#{resource[:name]}@([\d\.]+)/ =~ npm('outdated', '--global', resource[:name])
@latest = Regexp.last_match(1)
else
@property_hash[:ensure] unless @property_hash[:ensure].is_a? Symbol
end
end

def update
resource[:ensure] = @latest
self.install
install
end

def install
Expand Down
Loading

0 comments on commit cf06a87

Please sign in to comment.