Class: PuppetLibrary::Forge::Source

Inherits:
Abstract
  • Object
show all
Defined in:
lib/puppet_library/forge/source.rb

Overview

A forge that serves a module from its source on disk. Metadata (metadata.json) is generated on the fly.

Note: The module directory must have a Modulefile.

Constant Summary collapse

CACHE_TTL_MILLIS =
500

Instance Method Summary collapse

Methods inherited from Abstract

#collect_dependencies_versions, #get_module_buffer, #get_module_metadata, #get_module_metadata_with_dependencies, #retrieve_all_metadata, #retrieve_metadata, #search_modules

Constructor Details

#initialize(module_dir) ⇒ Source

  • :module_dir - The directory containing the module’s source.



33
34
35
36
37
38
39
40
# File 'lib/puppet_library/forge/source.rb', line 33

def initialize(module_dir)
    super(self)
    module_dir = File.expand_path(module_dir)
    raise "Module directory '#{module_dir}' doesn't exist" unless File.directory? module_dir
    raise "Module directory '#{module_dir}' isn't readable" unless File.executable? module_dir
    @module_dir = module_dir
    @cache = PuppetLibrary::Http::Cache::InMemory.new(CACHE_TTL_MILLIS)
end

Instance Method Details

#get_all_metadataObject



56
57
58
# File 'lib/puppet_library/forge/source.rb', line 56

def 
    (modulefile.get_author, modulefile.get_simple_name)
end

#get_metadata(author, module_name) ⇒ Object



51
52
53
54
# File 'lib/puppet_library/forge/source.rb', line 51

def (author, module_name)
    return [] unless this_module?(author, module_name)
    [ modulefile. ]
end

#get_module(author, name, version) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/puppet_library/forge/source.rb', line 42

def get_module(author, name, version)
    return nil unless this_module?(author, name, version)
    PuppetLibrary::Archive::Archiver.archive_dir(@module_dir, "#{author}-#{name}-#{version}") do |archive|
        archive.add_file("metadata.json", 0644) do |entry|
            entry.write modulefile..to_json
        end
    end
end