Class: OsCtl::Repo::Local::Index
- Inherits:
-
Object
- Object
- OsCtl::Repo::Local::Index
- Includes:
- Lib::Utils::File
- Defined in:
- lib/osctl/repo/local/index.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
protected
Returns the value of attribute contents.
-
#repo ⇒ Object
readonly
protected
Returns the value of attribute repo.
-
#vendors ⇒ Object
readonly
protected
Returns the value of attribute vendors.
Instance Method Summary collapse
- #add(image) ⇒ Object
- #delete(image) ⇒ Object
- #exist? ⇒ Boolean
- #find(vendor, variant, arch, distribution, version) ⇒ Object
- #images ⇒ Object
-
#initialize(repo) ⇒ Index
constructor
A new instance of Index.
- #path ⇒ Object protected
- #save ⇒ Object
- #set_default_variant(vendor, name) ⇒ Object
- #set_default_vendor(name) ⇒ Object
Constructor Details
#initialize(repo) ⇒ Index
Returns a new instance of Index.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/osctl/repo/local/index.rb', line 8 def initialize(repo) @repo = repo if exist? data = JSON.parse(File.read(path), symbolize_names: true) @vendors = data[:vendors] @contents = data[:images].map { |v| Base::Image.load(repo, v) } else @vendors = { default: nil } @contents = [] end end |
Instance Attribute Details
#contents ⇒ Object (readonly, protected)
Returns the value of attribute contents.
85 86 87 |
# File 'lib/osctl/repo/local/index.rb', line 85 def contents @contents end |
#repo ⇒ Object (readonly, protected)
Returns the value of attribute repo.
85 86 87 |
# File 'lib/osctl/repo/local/index.rb', line 85 def repo @repo end |
#vendors ⇒ Object (readonly, protected)
Returns the value of attribute vendors.
85 86 87 |
# File 'lib/osctl/repo/local/index.rb', line 85 def vendors @vendors end |
Instance Method Details
#add(image) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/osctl/repo/local/index.rb', line 26 def add(image) if (i = contents.index(image)) contents[i] = image else contents << image end return unless image..any? # Remove the image's tags from previous distribution images contents.each do |t| next if t == image \ || t.vendor != image.vendor \ || t.variant != image.variant \ || t.arch != image.arch \ || t.distribution != image.distribution \ t..delete_if { |tag| image..include?(tag) } end end |
#delete(image) ⇒ Object
58 59 60 |
# File 'lib/osctl/repo/local/index.rb', line 58 def delete(image) contents.delete(image) end |
#exist? ⇒ Boolean
22 23 24 |
# File 'lib/osctl/repo/local/index.rb', line 22 def exist? File.exist?(path) end |
#find(vendor, variant, arch, distribution, version) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/osctl/repo/local/index.rb', line 48 def find(vendor, variant, arch, distribution, version) contents.detect do |t| t.vendor == vendor \ && t.variant == variant \ && t.arch == arch \ && t.distribution == distribution \ && (t.version == version || t..include?(version)) end end |
#images ⇒ Object
79 80 81 |
# File 'lib/osctl/repo/local/index.rb', line 79 def images contents.clone end |
#path ⇒ Object (protected)
87 88 89 |
# File 'lib/osctl/repo/local/index.rb', line 87 def path File.join(repo.path, 'INDEX.json') end |
#save ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/osctl/repo/local/index.rb', line 70 def save regenerate_file(path, 0o644) do |f| f.write({ vendors:, images: contents.sort.map(&:dump) }.to_json) end end |
#set_default_variant(vendor, name) ⇒ Object
66 67 68 |
# File 'lib/osctl/repo/local/index.rb', line 66 def set_default_variant(vendor, name) vendors[vendor.to_sym] = name end |
#set_default_vendor(name) ⇒ Object
62 63 64 |
# File 'lib/osctl/repo/local/index.rb', line 62 def set_default_vendor(name) vendors[:default] = name end |