Skip to content

Commit

Permalink
Remove monkey patched Parser and just extend the class
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossg committed Feb 27, 2015
1 parent e4f0bba commit cb433ad
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 56 deletions.
10 changes: 9 additions & 1 deletion lib/librarian/puppet/environment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "librarian/environment"
require "librarian/puppet/dsl"
require "librarian/puppet/source"
require "librarian/puppet/lockfile/parser"
require "librarian/puppet/lockfile"

module Librarian
module Puppet
Expand All @@ -11,6 +11,14 @@ def adapter_name
"puppet"
end

def lockfile
Lockfile.new(self, lockfile_path)
end

def ephemeral_lockfile
Lockfile.new(self, nil)
end

def tmp_path
part = config_db["tmp"] || ".tmp"
project_path.join(part)
Expand Down
39 changes: 39 additions & 0 deletions lib/librarian/puppet/lockfile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Extend Lockfile to normalize module names from acme/mod to acme-mod
module Librarian
module Puppet
class Lockfile < Librarian::Lockfile

# Extend the parser to normalize module names in old .lock files, converting / to -
class Parser < Librarian::Lockfile::Parser

include Librarian::Puppet::Util

def extract_and_parse_sources(lines)
sources = super
sources.each do |source|
source[:manifests] = Hash[source[:manifests].map do |name,manifest|
[normalize_name(name), manifest]
end]
end
sources
end

def extract_and_parse_dependencies(lines, manifests_index)
# when looking up in manifests_index normalize the name beforehand
class << manifests_index
include Librarian::Puppet::Util
alias_method :old_lookup, :[]
define_method(:[]) { |k| self.old_lookup(normalize_name(k)) }
end
super(lines, manifests_index)
end

end

def load(string)
Parser.new(environment).parse(string)
end

end
end
end
55 changes: 0 additions & 55 deletions lib/librarian/puppet/lockfile/parser.rb

This file was deleted.

0 comments on commit cb433ad

Please sign in to comment.