Class: Rgit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rgit/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/rgit/configuration.rb', line 6

def filename
  @filename
end

#rootsObject (readonly)

Returns the value of attribute roots.



6
7
8
# File 'lib/rgit/configuration.rb', line 6

def roots
  @roots
end

Class Method Details

.create(filename = File.join(Dir.home, '.rgit.yml')) ⇒ Object



12
13
14
15
16
17
# 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')) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# 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')) ⇒ Object



19
20
21
# File 'lib/rgit/configuration.rb', line 19

def self.load(filename = File.join(Dir.home, '.rgit.yml'))
  Configuration.new(filename)
end

Instance Method Details

#add_root(path) ⇒ Object



23
24
25
26
# 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) ⇒ Object



39
40
41
42
43
44
45
# 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) ⇒ Object



28
29
30
# File 'lib/rgit/configuration.rb', line 28

def remove_root(path)
  @roots.delete path
end

#saveObject



32
33
34
35
36
37
# 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