Class: Darcs::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/darcs/repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repository

Returns a new instance of Repository.



10
11
12
13
# File 'lib/darcs/repository.rb', line 10

def initialize(path)
  @path = path
  @prefs_regexps = {}
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/darcs/repository.rb', line 8

def path
  @path
end

Class Method Details

.findObject

Finds the repository we are in. Returns nil if we are not in a repository



17
18
19
20
21
22
23
24
# File 'lib/darcs/repository.rb', line 17

def self.find
  path = Dir.getwd
  while !repository?(path)
    return nil if File.dirname(path) == path
    path = File.dirname(path)
  end
  self.new(path)
end

.repository?(path) ⇒ Boolean

Determines whether the specified path is a repository

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/darcs/repository.rb', line 27

def self.repository?(path)
  FileTest.directory?(File.join(path, '_darcs', 'patches')) &&
    FileTest.exists?(File.join(path, '_darcs', 'inventory'))
end

Instance Method Details

#binary?(name) ⇒ Boolean

Determines whether this file a binary file according to the patterns found in _darcs/prefs/binaries.

Returns:

  • (Boolean)


49
50
51
# File 'lib/darcs/repository.rb', line 49

def binary?(name)
  prefs_regexp_file_matches(name, 'binaries') 
end

#boring?(name) ⇒ Boolean

Determines whether this file a boring file according to the patterns found in _darcs/prefs/boring.

Returns:

  • (Boolean)


55
56
57
# File 'lib/darcs/repository.rb', line 55

def boring?(name)
  prefs_regexp_file_matches(name, 'boring')
end

#inventory_fileObject



43
44
45
# File 'lib/darcs/repository.rb', line 43

def inventory_file
  File.join(path, '_darcs', 'inventory')
end

#patchesObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/darcs/repository.rb', line 32

def patches
  if @patches.nil?
    @patches = []
    pi = nil
    File.open(inventory_file, 'r') do |f|
      @patches << Patch.new(self, pi) while pi = PatchInfo.read(f)
    end
  end
  @patches
end

#write_patch(patch_info) ⇒ Object



59
60
61
62
63
64
# File 'lib/darcs/repository.rb', line 59

def write_patch(patch_info)
  patch = Patch.new(self, patch_info)
  patch.write do |writer|
    yield writer
  end
end