Class: PuppetForgeServer::Backends::Directory

Inherits:
Object
  • Object
show all
Includes:
Utils::Archiver
Defined in:
lib/puppet_forge_server/backends/directory.rb

Constant Summary collapse

@@PRIORITY =

Give highest priority to locally hosted modules

0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Archiver

#read_from_archive

Constructor Details

#initialize(url, readonly = false) ⇒ Directory

Returns a new instance of Directory.



28
29
30
31
32
# File 'lib/puppet_forge_server/backends/directory.rb', line 28

def initialize(url, readonly = false)
  @module_dir = url
  @log = PuppetForgeServer::Logger.get
  @readonly = readonly
end

Instance Attribute Details

#PRIORITYObject (readonly)

Returns the value of attribute PRIORITY.



26
27
28
# File 'lib/puppet_forge_server/backends/directory.rb', line 26

def PRIORITY
  @PRIORITY
end

Instance Method Details

#get_file_buffer(relative_path) ⇒ Object



43
44
45
46
# File 'lib/puppet_forge_server/backends/directory.rb', line 43

def get_file_buffer(relative_path)
  path = Dir["#{@module_dir}/**/#{relative_path}"].first
  File.open(path, 'r') if path
end

#get_metadata(author, name, options = {}) ⇒ Object



38
39
40
41
# File 'lib/puppet_forge_server/backends/directory.rb', line 38

def (author, name, options = {})
  version = options[:version] ? options[:version] : '*'
  get_modules("#{author}-#{name}-#{version}.tar.gz", options)
end

#query_metadata(query, options = {}) ⇒ Object



34
35
36
# File 'lib/puppet_forge_server/backends/directory.rb', line 34

def (query, options = {})
  get_modules("*#{query}*.tar.gz", options)
end

#upload(file_data) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/puppet_forge_server/backends/directory.rb', line 48

def upload(file_data)
  return false if @readonly
  filename = File.join(@module_dir, file_data[:filename])
  return false if File.exist?(filename)
  File.open(filename, 'w') do |f|
    f.write(file_data[:tempfile].read)
  end
  true
end