class Getch::Gentoo::Use

Public Class Methods

new(pkg = nil) click to toggle source
# File lib/getch/gentoo/use.rb, line 4
def initialize(pkg = nil)
  @use_dir = "#{MOUNTPOINT}/etc/portage/package.use"
  @pkg = pkg
  @file = @pkg ? @pkg.match(/[\w]+$/) : nil
  @make = "#{MOUNTPOINT}/etc/portage/make.conf"
end

Public Instance Methods

add(*flags) click to toggle source
# File lib/getch/gentoo/use.rb, line 11
def add(*flags)
  @flags = flags.join(' ')
  write
end
add_global(*flags) click to toggle source
# File lib/getch/gentoo/use.rb, line 16
def add_global(*flags)
  @flags = flags
  write_global
end

Private Instance Methods

write() click to toggle source
# File lib/getch/gentoo/use.rb, line 23
def write
  content = "#{@pkg} #{@flags}\n"
  File.write("#{@use_dir}/#{@file}", content, mode: 'w')
end
write_global() click to toggle source
# File lib/getch/gentoo/use.rb, line 28
def write_global
  list = []

  @flags.each { |f|
    unless Helpers::grep?(@make, /#{f}/)
      list << f
    end
  }

  use = list.join(' ')
  line = "USE=\"${USE} #{use}\"\n"
  File.write(@make, line, mode: 'a')
end