lib/rubyfocus/fetchers/fetcher.rb in rubyfocus-0.4.0 vs lib/rubyfocus/fetchers/fetcher.rb in rubyfocus-0.5.1
- old
+ new
@@ -36,10 +36,28 @@
# Returns the contents of a given patch
def patch(filename)
raise RuntimeError, "Method Fetcher#patch called for abstract class Fetcher."
end
+ # Returns the latest patch
+ def head
+ @head ||= patches.sort.last
+ end
+
+ # Can you reach head from the given ID?
+ def can_reach_head_from?(id)
+ patch_array = patches.select{ |p| p.from_ids.include?(id) }
+ until patch_array.empty?
+ p = patch_array.first
+ return true if p == self.head
+
+ next_patches = patches.select{ |np| np.from_ids.include? p.to_id }
+ patch_array = patch_array[1..-1] + next_patches
+ end
+ return false
+ end
+
#---------------------------------------
# Patching methods
# Update the document as far as we can
def update_full(document)
@@ -63,10 +81,10 @@
# Collect the next patch to the document. If more than one patch can be applied,
# apply the latest one.
def next_patch(document)
all_possible_patches = self.patches.select{ |patch| patch.can_patch?(document) }
- return all_possible_patches.sort_by(&:time).last
+ return all_possible_patches.sort.first
end
#---------------------------------------
# Serialisation info
\ No newline at end of file