class Manifestly::Manifest

Attributes

items[R]
manifest_file[RW]
manifest_repository[RW]

Some meta info that some callers want to attach to the manifest

manifest_sha[RW]

Public Class Methods

get_lines_from_string(line_string) click to toggle source
# File lib/manifestly/manifest.rb, line 46
def self.get_lines_from_string(line_string)
  all_lines = line_string.split("\n")

  all_lines.each_with_object([]) do |line, lines|
    line.gsub!(/#.*/,'')
    line.strip!
    lines.push(line) if line != ''
  end
end
new() click to toggle source
# File lib/manifestly/manifest.rb, line 6
def initialize()
  @items = []
end
read_file(filename, repositories) click to toggle source
# File lib/manifestly/manifest.rb, line 32
def self.read_file(filename, repositories)
  content = File.read(filename)
  read_string(content, repositories)
end
read_string(string, repositories) click to toggle source
# File lib/manifestly/manifest.rb, line 37
def self.read_string(string, repositories)
  lines = get_lines_from_string(string)

  lines.each_with_object(Manifest.new) do |line, manifest|
    item = ManifestItem.from_file_string(line, repositories)
    manifest.add_item(item)
  end
end

Public Instance Methods

[](index) click to toggle source
# File lib/manifestly/manifest.rb, line 28
def [](index)
  @items[index]
end
add_item(manifest_item) click to toggle source
# File lib/manifestly/manifest.rb, line 18
def add_item(manifest_item)
  @items.push(manifest_item)
end
add_repository(repository) click to toggle source
# File lib/manifestly/manifest.rb, line 10
def add_repository(repository)
  @items.push(Manifestly::ManifestItem.new(repository))
end
empty?() click to toggle source
# File lib/manifestly/manifest.rb, line 71
def empty?
  items.empty?
end
includes?(repository) click to toggle source
# File lib/manifestly/manifest.rb, line 65
def includes?(repository)
  @items.any?{|item| item.repository.display_name == repository.display_name}
end
remove_repositories_by_index(indices) click to toggle source
# File lib/manifestly/manifest.rb, line 22
def remove_repositories_by_index(indices)
  indices.each{|index| @items[index] = nil}
  @items.compact!
  nil
end
remove_repository(repository) click to toggle source
# File lib/manifestly/manifest.rb, line 14
def remove_repository(repository)
  @items.reject!{|item| item.repository.display_name == repository.display_name}
end
write(filename, options={}) click to toggle source
# File lib/manifestly/manifest.rb, line 56
def write(filename, options={})
  File.open(filename, 'w') do |file|
    @items.sort_by!(&:repository_name)
    @items.each do |item|
      file.write(item.to_file_string(options) + "\n")
    end
  end
end