]> git.cworth.org Git - sup/blobdiff - lib/sup/source.rb
add #pipe-to-process to text-mode
[sup] / lib / sup / source.rb
index 00f2d072261a2f810b20a50aab0bf2656bf52a7c..6510aae8a738dba0b3d81acb617312a1e1334bec 100644 (file)
@@ -1,6 +1,11 @@
 module Redwood
 
-class SourceError < StandardError; end
+class SourceError < StandardError
+  def initialize *a
+    raise "don't instantiate me!" if SourceError.is_a?(self.class)
+    super
+  end
+end
 class OutOfSyncSourceError < SourceError; end
 class FatalSourceError < SourceError; end
 
@@ -31,7 +36,7 @@ class Source
   ## - load_header offset
   ## - load_message offset
   ## - raw_header offset
-  ## - raw_full_message offset
+  ## - raw_message offset
   ## - check
   ## - next (or each, if you prefer): should return a message and an
   ##   array of labels.
@@ -61,6 +66,8 @@ class Source
   attr_accessor :id
 
   def initialize uri, initial_offset=nil, usual=true, archived=false, id=nil
+    raise ArgumentError, "id must be an integer: #{id.inspect}" unless id.is_a? Fixnum if id
+
     @uri = uri
     @cur_offset = initial_offset
     @usual = usual
@@ -69,12 +76,14 @@ class Source
     @dirty = false
   end
 
+  def file_path; nil end
+
   def to_s; @uri.to_s; end
   def seek_to! o; self.cur_offset = o; end
   def reset!; seek_to! start_offset; end
   def == o; o.uri == uri; end
-  def done?; (self.cur_offset ||= start_offset) >= end_offset; end
-  def is_source_for? uri; URI(self.uri) == URI(uri); end
+  def done?; start_offset.nil? || (self.cur_offset ||= start_offset) >= end_offset; end
+  def is_source_for? uri; uri == @uri; end
 
   ## check should throw a FatalSourceError or an OutOfSyncSourcError
   ## if it can detect a problem. it is called when the sup starts up
@@ -92,6 +101,10 @@ class Source
 
 protected
   
+  def Source.expand_filesystem_uri uri
+    uri.gsub "~", File.expand_path("~")
+  end
+
   def cur_offset= o
     @cur_offset = o
     @dirty = true