Class: PuppetLibrary::Forge::Source

Inherits:
Abstract 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.

Usage:

forge = PuppetLibrary::Forge::Source.configure do
    # The path of the module's source
    path "/var/modules/mymodulesource"
end

Constant Summary collapse

CACHE_TTL_MILLIS =
500

Class Method Summary collapse

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

Methods inherited from Forge

#clear_cache, #prime

Constructor Details

#initialize(module_dir) ⇒ Source

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



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

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

Class Method Details

.configure(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/puppet_library/forge/source.rb', line 37

def self.configure(&block)
    config_api = PuppetLibrary::Util::ConfigApi.for(Source) do
        required :path, "path to the module's source" do |path|
            Dir.new(File.expand_path(path))
        end
    end
    config = config_api.configure(&block)
    Source.new(config.get_path)
end

Instance Method Details

#get_all_metadataObject



72
73
74
# File 'lib/puppet_library/forge/source.rb', line 72

def 
    (modulefile.get_author, modulefile.get_simple_name)
end

#get_metadata(author, module_name) ⇒ Object



67
68
69
70
# File 'lib/puppet_library/forge/source.rb', line 67

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

#get_module(author, name, version) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/puppet_library/forge/source.rb', line 58

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