Module: Amp::Repositories::CommonChangesetMethods

Included in:
AbstractChangeset
Defined in:
lib/amp/repository/abstract/common_methods/changeset.rb

Overview

CommonVersionedFileMethods

These methods are common to all repositories, and this module is mixed into the AbstractLocalRepository class. This guarantees that all repositories will have these methods.

No methods should be placed into this module unless it relies on methods in the general API for repositories.

Instance Method Summary collapse

Instance Method Details

#changed_filesHash<String => String>

A hash of the files that have been changed and their most recent diffs. The diffs are lazily made upon access. To just get the files, use #altered_files or #changed_files.keys Checks whether this changeset included a given file or not.

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/amp/repository/abstract/common_methods/changeset.rb', line 22

def changed_files
  h = {}
  class << h
    def [](*args)
      super(*args).call # we expect a proc
    end
  end
  
  altered_files.inject(h) do |s, k|
    s[k] = proc do
      other = parents.first[k]
      self[k].unified_diff other
    end
  end
end

#include?(file) ⇒ Boolean

Is file being tracked at this point in time?

Parameters:

  • file (String)

    the file to lookup

Returns:

  • (Boolean)

    whether the file is in this changeset’s manifest



43
44
45
# File 'lib/amp/repository/abstract/common_methods/changeset.rb', line 43

def include?(file)
  all_files.include? file
end

#walk(match) ⇒ Object

recursively walk

Parameters:

  • match (Amp::Matcher)

    this is a custom object that knows files magically. Not your grampa’s proc!



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/amp/repository/abstract/common_methods/changeset.rb', line 52

def walk(match)
  # just make it so the keys are there
  results = []
  
  hash = Hash.with_keys match.files
  hash.delete '.'
  
  each do |file|
    hash.each {|f, val| (hash.delete file and break) if f == file }
    
    results << file if match.call file # yield file if match.call file
  end
  
  hash.keys.sort.each do |file|
    if match.bad file, "No such file in revision #{revision}" and match[file]
      results << file # yield file
    end
  end
  results
end