Class: OsCtl::Repo::Remote::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/osctl/repo/remote/index.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, data) ⇒ Index

Returns a new instance of Index.



15
16
17
18
19
# File 'lib/osctl/repo/remote/index.rb', line 15

def initialize(repo, data)
  @repo = repo
  @vendors = data[:vendors]
  @contents = data[:images].map { |v| Remote::Image.load(repo, v) }
end

Instance Attribute Details

#contentsObject (readonly, protected)

Returns the value of attribute contents.



40
41
42
# File 'lib/osctl/repo/remote/index.rb', line 40

def contents
  @contents
end

#repoObject (readonly)

Returns the value of attribute repo.



13
14
15
# File 'lib/osctl/repo/remote/index.rb', line 13

def repo
  @repo
end

#vendorsObject (readonly, protected)

Returns the value of attribute vendors.



40
41
42
# File 'lib/osctl/repo/remote/index.rb', line 40

def vendors
  @vendors
end

Class Method Details

.from_file(repo, path) ⇒ Object



9
10
11
# File 'lib/osctl/repo/remote/index.rb', line 9

def self.from_file(repo, path)
  from_string(repo, File.read(path))
end

.from_string(repo, str) ⇒ Object



5
6
7
# File 'lib/osctl/repo/remote/index.rb', line 5

def self.from_string(repo, str)
  new(repo, JSON.parse(str, symbolize_names: true))
end

Instance Method Details

#imagesObject



34
35
36
# File 'lib/osctl/repo/remote/index.rb', line 34

def images
  @contents
end

#lookup(vendor, variant, arch, dist, vtag) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/osctl/repo/remote/index.rb', line 21

def lookup(vendor, variant, arch, dist, vtag)
  real_vendor = vendor == 'default' ? vendors[:default] : vendor
  real_variant = variant == 'default' ? vendors[real_vendor.to_sym] : variant

  contents.detect do |t|
    t.vendor == real_vendor \
      && t.variant == real_variant \
      && t.arch == arch \
      && t.distribution == dist \
      && (t.version == vtag || t.tags.include?(vtag))
  end
end