Class: Piston::Revision

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/piston/revision.rb

Direct Known Subclasses

Git::Commit, Svn::Revision

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, revision, recalled_values = {}) ⇒ Revision

Returns a new instance of Revision.



13
14
15
# File 'lib/piston/revision.rb', line 13

def initialize(repository, revision, recalled_values={})
  @repository, @revision, @recalled_values = repository, revision, recalled_values
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



11
12
13
# File 'lib/piston/revision.rb', line 11

def dir
  @dir
end

#recalled_valuesObject (readonly)

Returns the value of attribute recalled_values.



11
12
13
# File 'lib/piston/revision.rb', line 11

def recalled_values
  @recalled_values
end

#repositoryObject (readonly)

Returns the value of attribute repository.



11
12
13
# File 'lib/piston/revision.rb', line 11

def repository
  @repository
end

#revisionObject (readonly)

Returns the value of attribute revision.



11
12
13
# File 'lib/piston/revision.rb', line 11

def revision
  @revision
end

Class Method Details

.loggerObject



6
7
8
# File 'lib/piston/revision.rb', line 6

def logger
  @@logger ||= Log4r::Logger["handler"]
end

Instance Method Details

#checkout_to(dir) ⇒ Object

Retrieve a copy of this repository into dir.



38
39
40
41
# File 'lib/piston/revision.rb', line 38

def checkout_to(dir)
  logger.debug {"Checking out #{@repository}@#{@revision} into #{dir}"}
  @dir = dir.kind_of?(Pathname) ? dir : Pathname.new(dir)
end

#copy_from(abspath, relpath) ⇒ Object

Copies abspath (an absolute path) to relpath (relative to ourselves).

Raises:

  • (ArgumentError)


67
68
69
70
71
72
73
# File 'lib/piston/revision.rb', line 67

def copy_from(abspath, relpath)
  raise ArgumentError, "Revision #{revision} of #{repository.url} was never checked out -- can't iterate over files" unless @dir

  target = @dir + relpath
  Pathname.new(target).dirname.mkpath
  FileUtils.copy_entry(abspath, target) unless abspath.symlink?
end

#copy_to(relpath, abspath) ⇒ Object

Copies relpath (relative to ourselves) to abspath (an absolute path).

Raises:

  • (ArgumentError)


59
60
61
62
63
64
# File 'lib/piston/revision.rb', line 59

def copy_to(relpath, abspath)
  raise ArgumentError, "Revision #{revision} of #{repository.url} was never checked out -- can't iterate over files" unless @dir

  Pathname.new(abspath).dirname.mkpath
  FileUtils.copy_entry(@dir + relpath, abspath) unless abspath.symlink?
end

#eachObject

Yields each file of this revision in turn to our caller.



55
56
# File 'lib/piston/revision.rb', line 55

def each
end

#exclude_for_diffObject



79
80
81
# File 'lib/piston/revision.rb', line 79

def exclude_for_diff
  raise SubclassResponsibilityError, "Piston::Revision#exclude_for_diff should be implemented by a subclass."
end

#inspectObject



33
34
35
# File 'lib/piston/revision.rb', line 33

def inspect
  "Piston::Revision(#{@repository.url}@#{@revision})"
end

#loggerObject



25
26
27
# File 'lib/piston/revision.rb', line 25

def logger
  self.class.logger
end

#nameObject



21
22
23
# File 'lib/piston/revision.rb', line 21

def name
  @revision
end

#remember_valuesObject

What values does this revision want to remember for the future ?



49
50
51
52
# File 'lib/piston/revision.rb', line 49

def remember_values
  logger.debug {"Generating remember values"}
  {}
end

#remotely_modifiedObject



75
76
77
# File 'lib/piston/revision.rb', line 75

def remotely_modified
  raise SubclassResponsibilityError, "Piston::Revision#remotely_modified should be implemented by a subclass."
end

#to_sObject



29
30
31
# File 'lib/piston/revision.rb', line 29

def to_s
  "revision #{@revision}"
end

#update_to(to, lock) ⇒ Object

Update a copy of this repository to revision to.



44
45
46
# File 'lib/piston/revision.rb', line 44

def update_to(to, lock)
  raise SubclassResponsibilityError, "Piston::Revision#update_to should be implemented by a subclass."
end

#urlObject



17
18
19
# File 'lib/piston/revision.rb', line 17

def url
  repository.url
end