Class: SimplePuppetForge::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_puppet_forge/module.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/simple_puppet_forge/module.rb', line 5

def 
  @metadata
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/simple_puppet_forge/module.rb', line 5

def path
  @path
end

#uripathObject (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

#dependenciesObject



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_metadataObject

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

#nameObject



52
53
54
# File 'lib/simple_puppet_forge/module.rb', line 52

def name
  @metadata['name']
end

#read_metadataObject

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_hashObject



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

#versionObject



48
49
50
# File 'lib/simple_puppet_forge/module.rb', line 48

def version
  @metadata['version']
end