Class: RSCM::Revisions
- Inherits:
-
Object
- Object
- RSCM::Revisions
- Includes:
- Enumerable
- Defined in:
- lib/rscm/revisions.rb
Overview
A Revisions object is a collection of Revision objects with some additional behaviour.
Most importantly, it provides logic to group individual RevisionFile objects into Revision objects internally. This means that implementors of RSCM adapters that don’t support atomic changesets can still emulate them, simply by adding RevisionFile objects to a Revisions object. Example:
revisions = Revisions.new
revisions.add revision_file_1
revisions.add revision_file_2
revisions.add revision_file_3
The added RevisionFile objects will end up in Revision objects grouped by their comment, developer and timestamp. A set of RevisionFile object with identical developer and message will end up in the same Revision provided their time
attributes are a minute apart or less.
Each Revisions object also has an attribute cmd
which should contain the command used to retrieve the revision data and populate it. This is useful for debugging an RSCM adapter that might behaving incorrectly. Keep in mind that it is the responsibility of each RSCM adapter implementation to set this attribute, and that it should omit setting it if the store_revisions_command
is true
Instance Attribute Summary collapse
-
#cmd ⇒ Object
Returns the value of attribute cmd.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](n) ⇒ Object
- #add(file_or_revision) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(revisions = []) ⇒ Revisions
constructor
A new instance of Revisions.
- #length ⇒ Object
- #sort! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(revisions = []) ⇒ Revisions
Returns a new instance of Revisions.
34 35 36 |
# File 'lib/rscm/revisions.rb', line 34 def initialize(revisions=[]) @revisions = revisions end |
Instance Attribute Details
#cmd ⇒ Object
Returns the value of attribute cmd.
32 33 34 |
# File 'lib/rscm/revisions.rb', line 32 def cmd @cmd end |
Instance Method Details
#==(other) ⇒ Object
59 60 61 |
# File 'lib/rscm/revisions.rb', line 59 def ==(other) self.to_s == other.to_s end |
#[](n) ⇒ Object
67 68 69 |
# File 'lib/rscm/revisions.rb', line 67 def [](n) @revisions[n] end |
#add(file_or_revision) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rscm/revisions.rb', line 38 def add(file_or_revision) if(file_or_revision.is_a?(Revision)) @revisions << file_or_revision else revision = find { |a_revision| a_revision.accept?(file_or_revision) } if(revision.nil?) revision = Revision.new @revisions << revision end revision.add file_or_revision end end |
#each(&block) ⇒ Object
63 64 65 |
# File 'lib/rscm/revisions.rb', line 63 def each(&block) @revisions.each(&block) end |
#empty? ⇒ Boolean
75 76 77 |
# File 'lib/rscm/revisions.rb', line 75 def empty? @revisions.empty? end |
#length ⇒ Object
71 72 73 |
# File 'lib/rscm/revisions.rb', line 71 def length @revisions.length end |
#sort! ⇒ Object
51 52 53 |
# File 'lib/rscm/revisions.rb', line 51 def sort! @revisions.sort!{|r1,r2| r1.time<=>r2.time} end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/rscm/revisions.rb', line 55 def to_s @revisions.collect{|revision| revision.to_s}.join("\n-----------") end |