From 5511b35ef0154c0918e64f34910ea6d9b1366cad Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 16 Sep 2013 08:14:50 +0200 Subject: refactor - separate reading the last sequence from initialize --- lib/tapicero/couch_changes.rb | 18 +++++++++++------- 1 file 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 -- cgit v1.2.3