Class: PuppetLibrary::Forge::Source
- 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 either a metadata.json
or a Modulefile
. If it contains both, metadata.json
will be used.
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
- #get_all_metadata ⇒ Object
- #get_metadata(author, module_name) ⇒ Object
- #get_module(author, name, version) ⇒ Object
-
#initialize(module_dir) ⇒ Source
constructor
-
:module_dir
- The directory containing the module’s source.
-
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
Methods included from Util::Logging
#debug, #info, #logger, #logs, #warn
Constructor Details
#initialize(module_dir) ⇒ Source
-
:module_dir
- The directory containing the module’s source.
51 52 53 54 55 56 57 |
# File 'lib/puppet_library/forge/source.rb', line 51 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 @metadata_cache = PuppetLibrary::Http::Cache::InMemory.new(CACHE_TTL_MILLIS) end |
Class Method Details
.configure(&block) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet_library/forge/source.rb', line 38 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.(path)) end end config = config_api.configure(&block) Source.new(config.get_path) end |
Instance Method Details
#get_all_metadata ⇒ Object
73 74 75 |
# File 'lib/puppet_library/forge/source.rb', line 73 def (["author"], ["name"].split("-").last) end |
#get_metadata(author, module_name) ⇒ Object
68 69 70 71 |
# File 'lib/puppet_library/forge/source.rb', line 68 def (, module_name) return [] unless this_module?(, module_name) [ ] end |
#get_module(author, name, version) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/puppet_library/forge/source.rb', line 59 def get_module(, name, version) return nil unless this_module?(, name, version) PuppetLibrary::Archive::Archiver.archive_dir(@module_dir.path, "#{}-#{name}-#{version}") do |archive| archive.add_file("metadata.json", 0644) do |entry| entry.write .to_json end end end |