Class: Librarian::Puppet::Dsl::Receiver
- Inherits:
-
Dsl::Receiver
- Object
- Dsl::Receiver
- Librarian::Puppet::Dsl::Receiver
- Defined in:
- lib/librarian/puppet/dsl.rb
Instance Attribute Summary collapse
-
#specfile ⇒ Object
readonly
Returns the value of attribute specfile.
-
#working_path ⇒ Object
readonly
Returns the value of attribute working_path.
Instance Method Summary collapse
-
#metadata ⇒ Object
implement the ‘metadata’ syntax for Puppetfile.
-
#modulefile ⇒ Object
implement the ‘modulefile’ syntax for Puppetfile.
-
#run(specfile = nil) ⇒ Object
save the specfile and call librarian.
Instance Attribute Details
#specfile ⇒ Object (readonly)
Returns the value of attribute specfile.
41 42 43 |
# File 'lib/librarian/puppet/dsl.rb', line 41 def specfile @specfile end |
#working_path ⇒ Object (readonly)
Returns the value of attribute working_path.
41 42 43 |
# File 'lib/librarian/puppet/dsl.rb', line 41 def working_path @working_path end |
Instance Method Details
#metadata ⇒ Object
implement the ‘metadata’ syntax for Puppetfile
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/librarian/puppet/dsl.rb', line 61 def f = working_path.join('metadata.json') unless File.exists?(f) msg = "Metadata file does not exist: #{f}" # try modulefile, in case we don't have a Puppetfile and we are using the default template if File.exists?(modulefile_path) modulefile 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.each do |d| mod(d['name'], d['version_requirement']) end end |
#modulefile ⇒ Object
implement the ‘modulefile’ syntax for Puppetfile
51 52 53 54 55 56 57 58 |
# File 'lib/librarian/puppet/dsl.rb', line 51 def modulefile f = modulefile_path raise Error, "Modulefile file does not exist: #{f}" unless File.exists?(f) File.read(f).lines.each do |line| regexp = /\s*dependency\s+('|")([^'"]+)\1\s*(?:,\s*('|")([^'"]+)\3)?/ regexp =~ line && mod($2, $4) end end |
#run(specfile = nil) ⇒ Object
save the specfile and call librarian
44 45 46 47 48 |
# File 'lib/librarian/puppet/dsl.rb', line 44 def run(specfile = nil) @working_path = specfile.kind_of?(Pathname) ? specfile.parent : Pathname.new(Dir.pwd) @specfile = specfile super end |