Class: Vam::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/vam/repo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepo

Returns a new instance of Repo.



11
12
13
14
# File 'lib/vam/repo.rb', line 11

def initialize
  @repo_url = ''
  @vendors = {}
end

Instance Attribute Details

#repo_urlObject

Returns the value of attribute repo_url.



9
10
11
# File 'lib/vam/repo.rb', line 9

def repo_url
  @repo_url
end

Class Method Details

.dump(dir, repo) ⇒ Object



78
79
80
# File 'lib/vam/repo.rb', line 78

def self.dump(dir, repo)
  File.open(File.join(dir, 'repo'), 'w') {|f| f.write(Marshal.dump repo)}
end

.load(repo_url) ⇒ Object



71
72
73
74
75
# File 'lib/vam/repo.rb', line 71

def self.load(repo_url)
  repo = Marshal.load open(File.join(repo_url, 'repo'))
  repo.repo_url = repo_url
  repo
end

.scan(dir) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vam/repo.rb', line 55

def self.scan(dir)
  repo = Repo.new
  Dir.glob(File.join dir, '*').each do |s|
    name = File.basename(s)

    Dir.glob(File.join s, '*').each do |v|
      version = File.basename(v)
      files = Dir.glob(File.join v, '/**/*').reject{ |e| File.directory? e }.collect { |e| e.slice!("#{v}/"); e }
      repo.add name, version, files
    end
  end

  Repo.dump dir, repo
end

Instance Method Details

#add(name, version, rpath) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vam/repo.rb', line 38

def add(name, version, rpath)
  unless @vendors.include? name
    @vendors[name] = {}
  end

  unless @vendors[name].include? version
    @vendors[name][version] = []
  end

  if rpath.is_a? Array
    @vendors[name][version] = rpath
  else
    @vendors[name][version] << rpath
  end
end

#files(name, version) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vam/repo.rb', line 23

def files(name, version)
  unless @vendors.has_key? name and @vendors[name].has_key? version
    raise MissingComponentError, "Missing component with name [ #{name} ] and version [ #{version} ]"
  end

  @vendors[name][version].collect do |e|
    {
        dir: File.dirname(e),
        filename: File.basename(e),
        url: File.join(repo_url, name, version, e)
    }
  end
end

#latest_version(name) ⇒ Object



17
18
19
20
# File 'lib/vam/repo.rb', line 17

def latest_version(name)
  raise MissingComponentError, "Missing component with name [ #{name} ]" unless @vendors.has_key? name
  @vendors[name].keys.sort[0]
end