Class: RSCM::Revisions
- Inherits:
-
Object
- Object
- RSCM::Revisions
- Includes:
- Enumerable, XMLRPC::Marshallable
- Defined in:
- lib/rscm/revision.rb
Overview
A collection of Revision.
Instance Attribute Summary collapse
-
#revisions ⇒ Object
Returns the value of attribute revisions.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](file) ⇒ Object
-
#accept(visitor) ⇒ Object
Accepts a visitor that will receive callbacks while iterating over this instance’s internal structure.
-
#add(file_or_revision) ⇒ Object
Adds a File or a Revision.
-
#developers ⇒ Object
The set of developers that contributed to all of the contained Revision s.
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(revisions = []) ⇒ Revisions
constructor
A new instance of Revisions.
-
#latest ⇒ Object
The latest Revision (with the latest time) or nil if there are none.
- #length ⇒ Object
- #push(*file_or_revisions) ⇒ Object
- #reverse ⇒ Object
-
#sort! ⇒ Object
Sorts the revisions according to time.
Constructor Details
#initialize(revisions = []) ⇒ Revisions
Returns a new instance of Revisions.
14 15 16 |
# File 'lib/rscm/revision.rb', line 14 def initialize(revisions=[]) @revisions = revisions end |
Instance Attribute Details
#revisions ⇒ Object
Returns the value of attribute revisions.
12 13 14 |
# File 'lib/rscm/revision.rb', line 12 def revisions @revisions end |
Instance Method Details
#==(other) ⇒ Object
49 50 51 52 |
# File 'lib/rscm/revision.rb', line 49 def ==(other) return false if !other.is_a?(self.class) @revisions == other.revisions end |
#[](file) ⇒ Object
31 32 33 |
# File 'lib/rscm/revision.rb', line 31 def [](file) @revisions[file] end |
#accept(visitor) ⇒ Object
Accepts a visitor that will receive callbacks while iterating over this instance’s internal structure. The visitor should respond to the following methods:
-
visit_revisions(revisions)
-
visit_revision(revision)
-
visit_file(file)
26 27 28 29 |
# File 'lib/rscm/revision.rb', line 26 def accept(visitor) visitor.visit_revisions(self) self.each{|revision| revision.accept(visitor)} end |
#add(file_or_revision) ⇒ Object
Adds a File or a Revision. If the argument is a File and no corresponding Revision exists, a new Revision is created, added, and the File is added to that Revision - and then finally the newly created Revision is returned. Otherwise nil is returned.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rscm/revision.rb', line 82 def add(file_or_revision) if(file_or_revision.is_a?(Revision)) @revisions << file_or_revision return file_or_revision else revision = @revisions.find { |a_revision| a_revision.can_contain?(file_or_revision) } if(revision.nil?) revision = Revision.new @revisions << revision revision << file_or_revision return revision end revision << file_or_revision return nil end end |
#developers ⇒ Object
The set of developers that contributed to all of the contained Revision s.
59 60 61 62 63 64 65 |
# File 'lib/rscm/revision.rb', line 59 def developers result = [] each do |revision| result << revision.developer unless result.index(revision.developer) end result end |
#each(&block) ⇒ Object
35 36 37 |
# File 'lib/rscm/revision.rb', line 35 def each(&block) @revisions.each(&block) end |
#empty? ⇒ Boolean
54 55 56 |
# File 'lib/rscm/revision.rb', line 54 def empty? @revisions.empty? end |
#latest ⇒ Object
The latest Revision (with the latest time) or nil if there are none.
69 70 71 72 73 74 75 |
# File 'lib/rscm/revision.rb', line 69 def latest result = nil each do |revision| result = revision if result.nil? || result.time < revision.time end result end |
#length ⇒ Object
45 46 47 |
# File 'lib/rscm/revision.rb', line 45 def length @revisions.length end |
#push(*file_or_revisions) ⇒ Object
99 100 101 102 |
# File 'lib/rscm/revision.rb', line 99 def push(*file_or_revisions) file_or_revisions.each { |file_or_revision| self << (file_or_revision) } self end |
#reverse ⇒ Object
39 40 41 42 43 |
# File 'lib/rscm/revision.rb', line 39 def reverse r = clone r.revisions = @revisions.dup.reverse r end |
#sort! ⇒ Object
Sorts the revisions according to time
105 106 107 108 |
# File 'lib/rscm/revision.rb', line 105 def sort! @revisions.sort! self end |