Class: RSCM::Revision

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

Overview

Represents a collection of File that were committed at the same time. Non-transactional SCMs (such as CVS and StarTeam) emulate Revision by grouping File s that were committed by the same developer, with the same commit message, and within a “reasonably” small timespan.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files = []) ⇒ Revision

Returns a new instance of Revision.



126
127
128
# File 'lib/rscm/revision.rb', line 126

def initialize(files=[])
  @files = files
end

Instance Attribute Details

#developerObject

Returns the value of attribute developer.



122
123
124
# File 'lib/rscm/revision.rb', line 122

def developer
  @developer
end

#filesObject (readonly)

Returns the value of attribute files.



120
121
122
# File 'lib/rscm/revision.rb', line 120

def files
  @files
end

#identifierObject

Returns the value of attribute identifier.



121
122
123
# File 'lib/rscm/revision.rb', line 121

def identifier
  @identifier
end

#messageObject

Returns the value of attribute message.



123
124
125
# File 'lib/rscm/revision.rb', line 123

def message
  @message
end

#timeObject

Returns the value of attribute time.



124
125
126
# File 'lib/rscm/revision.rb', line 124

def time
  @time
end

Instance Method Details

#<<(file) ⇒ Object



135
136
137
138
139
140
141
142
143
# File 'lib/rscm/revision.rb', line 135

def << (file)
  @files << file
  if(self.time.nil? || self.time < file.time unless file.time.nil?)
    self.time = file.time
    self.identifier = self.time if(self.identifier.nil? || self.identifier.is_a?(Time))
  end
  self.developer = file.developer if file.developer
  self.message = file.message if file.message
end

#<=>(other) ⇒ Object



172
173
174
# File 'lib/rscm/revision.rb', line 172

def <=>(other)
  @time <=> other.time
end

#==(other) ⇒ Object



167
168
169
170
# File 'lib/rscm/revision.rb', line 167

def ==(other)
  return false if !other.is_a?(self.class)
  @files == other.files
end

#[](file) ⇒ Object



145
146
147
# File 'lib/rscm/revision.rb', line 145

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

#accept(visitor) ⇒ Object



130
131
132
133
# File 'lib/rscm/revision.rb', line 130

def accept(visitor)
  visitor.visit_revision(self)
  @files.each{|file| file.accept(visitor)}
end

#can_contain?(file) ⇒ Boolean

Whether this instance can contain a File. Used by non-transactional SCMs.

Returns:

  • (Boolean)


178
179
180
181
182
# File 'lib/rscm/revision.rb', line 178

def can_contain?(file)
  self.developer == file.developer &&
  self.message == file.message &&
  (self.time - file.time).abs < 60
end

#each(&block) ⇒ Object



149
150
151
# File 'lib/rscm/revision.rb', line 149

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

#identifierAAObject

Returns the identifier of the revision. This is the revision (if defined) or an UTC time if it is not natively supported by the scm.



195
196
197
# File 'lib/rscm/revision.rb', line 195

def identifierAA
  @identifier || @time
end

#lengthObject



157
158
159
# File 'lib/rscm/revision.rb', line 157

def length
  @files.length
end

#popObject



153
154
155
# File 'lib/rscm/revision.rb', line 153

def pop
  @files.pop
end

#to_sObject

String representation that can be used for debugging.



185
186
187
188
189
190
191
# File 'lib/rscm/revision.rb', line 185

def to_s
  result = "#{identifier} | #{developer} | #{time} | #{message}\n"
  self.each do |file|
    result << " " << file.to_s << "\n"
  end
  result
end