class Pkgfile

Functionality for retrieving package and repository information from the Pkgfile

Public Class Methods

new(pkgfile_lines) click to toggle source
# File lib/Pkgfile.rb, line 4
def initialize(pkgfile_lines)
  @current_array = nil
  pkgfile_lines.each do |line|
    next if line.match(/^#/) #Skip comments
    
    if line.match(/^\[.*\]/) #an array is specified on this line
      @current_array = line[1..-3] #update current array name
      #create new array if one doesn't exist yet with this name
      instance_variable_set("@#{@current_array}", []) if not instance_variables.include? "@#{@current_array}"
      #process next line of pkgfile
      next
    end
    #skip line in case text found before an array was specified via '[array_name]'
    next if @current_array.nil?
    #Append value of line to current array, removing preceding and trailing whitespace
    instance_variable_set("@#{@current_array}", instance_variable_get("@#{@current_array}") << line.strip)
  end
  #Create attr_reader methods for all instance variables
  instance_variables.each do |ivar|
    if ivar[1..-1] == "repo"
      #Repo reader method returns a hash as {:repo_name => "repo_url"}
      self.class.send(:define_method, "add_repos") {repo_to_h}
      next
    end
    #create normal reader methods
    self.class.send(:define_method, ivar[1..-1]) {instance_variable_get("#{ivar}")}
  end

end

Private Instance Methods

repo_to_h() click to toggle source

converts values of @repo to a hash: {:repo_name => “repo_url”} + removes preceding and trailing whitespace

# File lib/Pkgfile.rb, line 36
def repo_to_h
  h = {}
  @repo.each do |val| 
    a = val.partition("=>")
    h[a[0].strip.to_sym] = a[2].strip
  end
  h
end