class Simp::Metadata::Engine

Attributes

options[RW]
sources[RW]
ssh_key[RW]

Public Class Methods

new(cachepath = nil, metadatarepos = nil, edition = 'community', options = {}) click to toggle source
# File lib/simp/metadata/engine.rb, line 11
def initialize(cachepath = nil, metadatarepos = nil, edition = 'community', options = {})
  ENV['GIT_SSH'] = "#{File.dirname(__FILE__)}/git_ssh_wrapper.sh"
  unless options['ssh_key'].nil?
    ENV['SIMP_METADATA_SSHKEY'] = (options['ssh_key']).to_s
  end
  @options = options
  @sources = {}
  @writable_source = 'simp-metadata'
  priority = 0
  bootstrap_source = Simp::Metadata::Bootstrap_source.new(edition)
  if metadatarepos.class.to_s == 'Hash'
    metadatarepos.each do |reponame, url|
      if url.match?(/https?:\/\/|git@/)
        method = 'git'
        extract = false
      else
        method = 'file'
        extract = true
      end
      # XXX: ToDo replace with better logic once Simp::Metadata.download_component gets refactored.
      # MUCH LAYERING VIOLATIONS
      next unless bootstrap_source.components.key?(reponame)
      bootstrap_source.components[reponame]['locations'][0]['url'] = url
      bootstrap_source.components[reponame]['locations'][0]['method'] = method
      bootstrap_source.components[reponame]['locations'][0]['extract'] = extract
    end
  end
  @sources[bootstrap_source.name] = bootstrap_source
  components.keys.each do |key|
    component = components[key]
    @sources[key] = Simp::Metadata::Source.new({ name: key, component: component }.merge(cachepath: cachepath, edition: edition, engine: self))
  end
end

Public Instance Methods

cleanup() click to toggle source
# File lib/simp/metadata/engine.rb, line 93
def cleanup
  @sources.each do |_name, source|
    source.cleanup
  end
end
components() click to toggle source
# File lib/simp/metadata/engine.rb, line 45
def components
  Simp::Metadata::Components.new(self)
end
dirty?() click to toggle source
# File lib/simp/metadata/engine.rb, line 53
def dirty?
  dirty = false
  @sources.each do |_name, source|
    dirty = true if source.dirty?
  end
  dirty
end
releases() click to toggle source
# File lib/simp/metadata/engine.rb, line 49
def releases
  Simp::Metadata::Releases.new(self)
end
save(message = 'Auto-saving using simp-metadata') click to toggle source
# File lib/simp/metadata/engine.rb, line 77
def save(message = 'Auto-saving using simp-metadata')
  Simp::Metadata.debug2('Saving metadata')
  @sources.each do |_name, source|
    if source.dirty?
      Simp::Metadata.debug1("#{source} - dirty, saving")
      source.save(message)
    else
      Simp::Metadata.debug1("#{source} - clean, not saving")
    end
  end
end
writable_source() click to toggle source
# File lib/simp/metadata/engine.rb, line 69
def writable_source
  @sources[@writable_source]
end
writable_source_name() click to toggle source
# File lib/simp/metadata/engine.rb, line 65
def writable_source_name
  @writable_source
end
writable_source_name=(source) click to toggle source
# File lib/simp/metadata/engine.rb, line 61
def writable_source_name=(source)
  @writable_source = source
end
writable_url(metadata_name, url) click to toggle source
# File lib/simp/metadata/engine.rb, line 73
def writable_url(metadata_name, url)
  @sources[metadata_name].write_url = url
end