summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2013-09-16 08:14:50 +0200
committerAzul <azul@riseup.net>2013-09-16 08:14:50 +0200
commit5511b35ef0154c0918e64f34910ea6d9b1366cad (patch)
tree4e6bebfbb7a94f20619225ff2f01cf3788c40879
parent37f87300c9804bdad66d730b676715e242b9ca42 (diff)
refactor - separate reading the last sequence from initialize
-rw-r--r--lib/tapicero/couch_changes.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/tapicero/couch_changes.rb b/lib/tapicero/couch_changes.rb
index 3b7da59..55a5489 100644
--- a/lib/tapicero/couch_changes.rb
+++ b/lib/tapicero/couch_changes.rb
@@ -9,13 +9,7 @@ module Tapicero
def initialize(db, seq_filename)
@db = db
@seq_filename = seq_filename
- FileUtils.touch(seq_filename)
- unless File.writable?(seq_filename)
- raise StandardError.new("Can't access sequence file")
- end
- @since = File.read(seq_filename)
- rescue Errno::ENOENT => e
- puts "No sequence file found. Starting from scratch"
+ read_seq(seq_filename)
end
def created(hash = {}, &block)
@@ -49,6 +43,16 @@ module Tapicero
#updated callback
end
+ def read_seq(seq_filename)
+ FileUtils.touch(seq_filename)
+ unless File.writable?(seq_filename)
+ raise StandardError.new("Can't access sequence file")
+ end
+ @since = File.read(seq_filename)
+ rescue Errno::ENOENT => e
+ puts "No sequence file found. Starting from scratch"
+ end
+
def store_seq(seq)
File.write(@seq_filename, seq)
end