lib/downlow/fetcher.rb in downlow-0.1.3 vs lib/downlow/fetcher.rb in downlow-0.1.4
- old
+ new
@@ -1,43 +1,43 @@
module Downlow
class Fetcher
-
+
def self.handles(which)
@@handlers ||= []
@@handlers << [which, self]
end
-
+
def self.fetcher_for(url)
@@handlers.each do |matcher, klass|
return klass if matcher.match url
end
end
-
+
def self.fetch(url, options = {})
klass = fetcher_for(url)
fetcher = klass.new(url, options)
fetcher.fetch
fetcher.local_path
end
-
+
attr_reader :url, :options, :local_path
attr_accessor :tmp_dir, :destination
-
+
def initialize(url, options = {})
@url = Pathname.new(url)
@options = options
@tmp_dir = Pathname.new(options[:tmp_dir] || 'tmp').expand_path + 'fetch'
@tmp_dir.mkpath
@destination = Pathname.new(options[:destination] || tmp_dir + self.url.basename ).expand_path
@destination.dirname.mkpath
end
-
+
def fetch
raise "Should be overridden by subclass"
end
-
+
def fetched?
!!@local_path
end
-
+
end
-end
\ No newline at end of file
+end