Class: SimplePuppetForge::Module
- Inherits:
-
Object
- Object
- SimplePuppetForge::Module
- Defined in:
- lib/simple_puppet_forge/module.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uripath ⇒ Object
readonly
Returns the value of attribute uripath.
Instance Method Summary collapse
- #dependencies ⇒ Object
-
#extract_metadata ⇒ Object
Extract the metdata if it doesn’t exist or if the module has been updated.
-
#initialize(path, uri_root_path) ⇒ Module
constructor
A new instance of Module.
- #name ⇒ Object
-
#read_metadata ⇒ Object
Read the metadata file.
- #to_hash ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(path, uri_root_path) ⇒ Module
Returns a new instance of Module.
7 8 9 10 11 12 13 14 |
# File 'lib/simple_puppet_forge/module.rb', line 7 def initialize(path, uri_root_path) @path = path @uripath = '/modules' + path[uri_root_path.chomp('/').length..-1].chomp('/') @metadata_path = path + '.metadata' end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/simple_puppet_forge/module.rb', line 5 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/simple_puppet_forge/module.rb', line 5 def path @path end |
#uripath ⇒ Object (readonly)
Returns the value of attribute uripath.
5 6 7 |
# File 'lib/simple_puppet_forge/module.rb', line 5 def uripath @uripath end |
Instance Method Details
#dependencies ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/simple_puppet_forge/module.rb', line 40 def dependencies @metadata['dependencies'].collect do |dep| ret = [dep['name']] ret << dep['version_requirement'] if dep['version_requirement'] ret end end |
#extract_metadata ⇒ Object
Extract the metdata if it doesn’t exist or if the module has been updated
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_puppet_forge/module.rb', line 17 def if File.exist?(@metadata_path) if File.stat(@metadata_path).mtime > File.stat(@path).mtime return end end # TODO: support others than GNU tar `tar -z -x -O --wildcards -f #{@path} '*/metadata.json' > #{@metadata_path}` raise "Failed to extract metadata for #{@path}" unless $?.success? end |
#name ⇒ Object
52 53 54 |
# File 'lib/simple_puppet_forge/module.rb', line 52 def name @metadata['name'] end |
#read_metadata ⇒ Object
Read the metadata file
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/simple_puppet_forge/module.rb', line 29 def begin = File.open(@metadata_path, 'r') @metadata = JSON.parse .read .close @metadata rescue raise "Failed to read metadata file #{@metadata_path}" end end |
#to_hash ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/simple_puppet_forge/module.rb', line 56 def to_hash { 'file' => @uripath, 'version' => version, 'dependencies' => dependencies, } end |
#version ⇒ Object
48 49 50 |
# File 'lib/simple_puppet_forge/module.rb', line 48 def version @metadata['version'] end |