lib/librarian/puppet/dsl.rb in librarian-puppet-1.5.0 vs lib/librarian/puppet/dsl.rb in librarian-puppet-2.0.0
- old
+ new
@@ -1,42 +1,42 @@
require 'librarian/dsl'
require 'librarian/dsl/target'
require 'librarian/puppet/source'
-require 'librarian/puppet/dependency'
module Librarian
module Puppet
class Dsl < Librarian::Dsl
- FORGE_URL = "http://forge.puppetlabs.com"
-
dependency :mod
source :forge => Source::Forge
source :git => Source::Git
source :path => Source::Path
source :github_tarball => Source::GitHubTarball
- def default_specfile
- Proc.new do
- forge FORGE_URL
- metadata
+ # copied from Librarian::Dsl to use our own Receiver
+ def run(specfile = nil, sources = [])
+ specfile, sources = nil, specfile if specfile.kind_of?(Array) && sources.empty?
+
+ if specfile.kind_of?(Pathname) and !File.exists?(specfile)
+ debug { "Specfile not found, using defaults: #{specfile}" }
+ specfile = Proc.new do
+ forge "https://forgeapi.puppetlabs.com"
+ metadata
+ end
end
- end
- def self.dependency_type
- Librarian::Puppet::Dependency
- end
+ Target.new(self).tap do |target|
+ target.precache_sources(sources)
+ debug_named_source_cache("Pre-Cached Sources", target)
- def post_process_target(target)
- # save the default forge defined
- default_forge = target.sources.select {|s| s.is_a? Librarian::Puppet::Source::Forge}.first
- Librarian::Puppet::Source::Forge.default = default_forge || Librarian::Puppet::Source::Forge.from_lock_options(environment, :remote => FORGE_URL)
- end
+ specfile ||= Proc.new if block_given?
+ receiver = Receiver.new(target)
+ receiver.run(specfile)
- def receiver(target)
- Receiver.new(target)
+ debug_named_source_cache("Post-Cached Sources", target)
+ end.to_spec
end
class Receiver < Librarian::Dsl::Receiver
attr_reader :specfile, :working_path
@@ -68,15 +68,10 @@
return
else
raise Error, msg
end
end
- begin
- json = JSON.parse(File.read(f))
- rescue JSON::ParserError => e
- raise Error, "Unable to parse json file #{f}: #{e}"
- end
- dependencyList = json['dependencies']
+ dependencyList = JSON.parse(File.read(f))['dependencies']
dependencyList.each do |d|
mod(d['name'], d['version_requirement'])
end
end