Class: RSCM::Revision

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

Overview

Represents a collection of RevisionFile that were committed at the same time, or “more or less at the same time” for non-atomic SCMs (such as CVS and StarTeam). See Revisions for how to emulate atomicity for non-atomic SCMs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier = nil, time = nil) ⇒ Revision

Returns a new instance of Revision.



17
18
19
20
21
# File 'lib/rscm/revision.rb', line 17

def initialize(identifier=nil, time=nil)
  @identifier = identifier
  @time = time
  @files = []
end

Instance Attribute Details

#developerObject

Returns the value of attribute developer.



14
15
16
# File 'lib/rscm/revision.rb', line 14

def developer
  @developer
end

#identifier(min_or_max = :max) ⇒ Object



30
31
32
# File 'lib/rscm/revision.rb', line 30

def identifier(min_or_max = :max)
  @identifier || time(min_or_max)
end

#messageObject

Returns the value of attribute message.



15
16
17
# File 'lib/rscm/revision.rb', line 15

def message
  @message
end

Instance Method Details

#==(other) ⇒ Object



63
64
65
# File 'lib/rscm/revision.rb', line 63

def ==(other)
  self.to_s == other.to_s
end

#[](n) ⇒ Object



86
87
88
# File 'lib/rscm/revision.rb', line 86

def [](n)
  @files[n]
end

#accept?(file) ⇒ Boolean

Whether file can be added to this instance.

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rscm/revision.rb', line 51

def accept?(file) #:nodoc:
  return true if empty? || @time

  close_enough_to_min = (time(:min) - file.time).abs <= 60
  close_enough_to_max = (time(:max) - file.time).abs <= 60
  close_enough = close_enough_to_min or close_enough_to_max

  close_enough and
  self.developer == file.developer and
  self.message == file.message
end

#add(file) ⇒ Object



23
24
25
26
27
28
# File 'lib/rscm/revision.rb', line 23

def add(file)
  raise "Can't add #{file} to this revision" unless accept? file
  @files << file
  self.developer = file.developer if file.developer
  self.message = file.message if file.message
end

#each(&block) ⇒ Object



82
83
84
# File 'lib/rscm/revision.rb', line 82

def each(&block)
  @files.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/rscm/revision.rb', line 98

def empty?
  @files.empty?
end

#lengthObject



90
91
92
# File 'lib/rscm/revision.rb', line 90

def length
  @files.length
end

#popObject



94
95
96
# File 'lib/rscm/revision.rb', line 94

def pop
  @files.pop
end

#time(min_or_max = :max) ⇒ Object

The time of this revision. Depending on the value of min_or_max, (should be :min or :max), returns the min or max time of this revision. (min or max only matters for non-transactional scms)



37
38
39
# File 'lib/rscm/revision.rb', line 37

def time(min_or_max = :max)
  @time || self.collect{|file| file.time}.__send__(min_or_max)
end

#time=(t) ⇒ Object

Sets the time for this revision. Should only be used by atomic SCMs. Non-atomic SCMs should not invoke this method, but instead create revisions by adding RscmFile objects to a Revisions object.



44
45
46
47
48
# File 'lib/rscm/revision.rb', line 44

def time=(t)
  raise "time must be a Time object - it was a #{t.class.name} with the string value #{t}" unless t.is_a?(Time)
  raise "can't set time to an inferiour value than the previous value" if @time && (t < @time)
  @time = t
end

#to_sObject

String representation that can be used for debugging.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rscm/revision.rb', line 68

def to_s
  if(@to_s.nil?)
    min = time(:min)
    max = time(:max)
    t = (min==max) ? min : "#{min}-#{max}"
    @to_s = "#{identifier} | #{developer} | #{t} | #{message}\n"
    self.each do |file|
      @to_s << " " << file.to_s << "\n"
    end
    @to_s
  end
  @to_s
end