Sha256: 1fb59a1406f98abc0647762c0b02534a0f73fd155e7068ec0408f61780946d30

Contents?: true

Size: 685 Bytes

Versions: 3

Compression:

Stored size: 685 Bytes

Contents

require 'md5'
require 'uri'

module Feedzirra
  module Backend
    class Filesystem
      
      DEFAULTS = {
        :path => File.expand_path(File.join(%w[ ~ / .feedzirra ]))
      }
      
      def initialize(options = { })
        @options = DEFAULTS.merge(options)
      end
      
      def get(url)
        f = filename_for(url)
        Marshal.load(File.read(f)) if File.exist?(f)
      end
    
      def set(url, result)
        File.open(filename_for(url), 'w') {|f| f.write(Marshal.dump(result)) }
      end
      
      private
      
      def filename_for(url)
        File.join(@options[:path], MD5.hexdigest(URI.parse(url).normalize.to_s))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jsl-feedzirra-0.0.12.3 lib/feedzirra/backend/filesystem.rb
jsl-feedzirra-0.0.12.4 lib/feedzirra/backend/filesystem.rb
jsl-feedzirra-0.0.12.5 lib/feedzirra/backend/filesystem.rb