class Rgit::Configuration

Attributes

filename[R]
roots[R]

Public Class Methods

create(filename = File.join(Dir.home, '.rgit.yml')) click to toggle source
# File lib/rgit/configuration.rb, line 12
def self.create(filename = File.join(Dir.home, '.rgit.yml'))
  FileUtils.touch(filename)
  config = Configuration.new(filename)
  config.save
  config
end
exist?(filename = File.join(Dir.home, '.rgit.yml')) click to toggle source
# File lib/rgit/configuration.rb, line 8
def self.exist?(filename = File.join(Dir.home, '.rgit.yml'))
  File.exist?(filename)
end
load(filename = File.join(Dir.home, '.rgit.yml')) click to toggle source
# File lib/rgit/configuration.rb, line 19
def self.load(filename = File.join(Dir.home, '.rgit.yml'))
  Configuration.new(filename)
end
new(filename) click to toggle source
# File lib/rgit/configuration.rb, line 49
def initialize(filename)
  @filename = filename
  @roots = []

  return if File.size(filename).zero?

  yaml = YAML.load_file(filename)
  @roots = yaml['roots']
end

Public Instance Methods

add_root(path) click to toggle source
# File lib/rgit/configuration.rb, line 23
def add_root(path)
  raise '"/" path unsupported!' if path == '/'
  @roots << path unless @roots.include? path
end
find_root(path) click to toggle source
# File lib/rgit/configuration.rb, line 39
def find_root(path)
  until @roots.include?(path)
    path = File.expand_path('..', path)
    raise 'Not in a root directory' if path == '/'
  end
  path
end
remove_root(path) click to toggle source
# File lib/rgit/configuration.rb, line 28
def remove_root(path)
  @roots.delete path
end
save() click to toggle source
# File lib/rgit/configuration.rb, line 32
def save
  config = { 'roots' => @roots }
  File.open(@filename, 'w') do |f|
    f.write config.to_yaml
  end
end