Class: Simp::Metadata::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/simp/metadata/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cachepath = nil, metadatarepos = nil, edition = 'community', options = {}) ⇒ Engine

Returns a new instance of Engine.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/simp/metadata/engine.rb', line 8

def options
  @options
end

#sourcesObject

Returns the value of attribute sources.



9
10
11
# File 'lib/simp/metadata/engine.rb', line 9

def sources
  @sources
end

#ssh_keyObject

Returns the value of attribute ssh_key.



89
90
91
# File 'lib/simp/metadata/engine.rb', line 89

def ssh_key
  @ssh_key
end

Instance Method Details

#cleanupObject



93
94
95
96
97
# File 'lib/simp/metadata/engine.rb', line 93

def cleanup
  @sources.each do |_name, source|
    source.cleanup
  end
end

#componentsObject



45
46
47
# File 'lib/simp/metadata/engine.rb', line 45

def components
  Simp::Metadata::Components.new(self)
end

#dirty?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# 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

#releasesObject



49
50
51
# File 'lib/simp/metadata/engine.rb', line 49

def releases
  Simp::Metadata::Releases.new(self)
end

#save(message = 'Auto-saving using simp-metadata') ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# 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_sourceObject



69
70
71
# File 'lib/simp/metadata/engine.rb', line 69

def writable_source
  @sources[@writable_source]
end

#writable_source_nameObject



65
66
67
# File 'lib/simp/metadata/engine.rb', line 65

def writable_source_name
  @writable_source
end

#writable_source_name=(source) ⇒ Object



61
62
63
# File 'lib/simp/metadata/engine.rb', line 61

def writable_source_name=(source)
  @writable_source = source
end

#writable_url(metadata_name, url) ⇒ Object



73
74
75
# File 'lib/simp/metadata/engine.rb', line 73

def writable_url(, url)
  @sources[].write_url = url
end