Sha256: 96b6ac3bd72f3ef05502bb7d5f351d699fd7a1a610e14a84049cf1ff8ea4277f

Contents?: true

Size: 830 Bytes

Versions: 10

Compression:

Stored size: 830 Bytes

Contents

#
class Kernel
  attr_accessor :html_cache_dir
  @html_cache_dir = '/tmp'

  # cache any files read using http protocol
  def open_cache(url)
    if url =~ /^https?:\/\//i
      filespec = url.gsub(/^http:\//, @html_cache_dir).gsub(/\/$/, '.html')
      begin
        fh = open(filespec)
      rescue Exception
        fh = open(url)
        cache_html_files(filespec, fh.read)
        fh.rewind
      end
    else
      fh = open(url)
    end
    fh
  end

  private

  # this is used to save imdb pages so they may be used by rspec
  def cache_html_files(filespec, html)
    begin
      unless File.exist?(filespec)
        puts "caching #{filespec}"
        File.mkdirs(File.dirname(filespec))
        File.open(filespec, 'w') { |f| f.puts html }
      end
    rescue Exception => eMsg
      puts eMsg.to_s
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
royw-dvdprofiler2xbmc-0.0.12 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.0.13 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.0.15 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.0.17 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.0.18 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.0.19 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.0.6 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.0.8 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.1.0 lib/dvdprofiler2xbmc/open_cache_extension.rb
royw-dvdprofiler2xbmc-0.1.2 lib/dvdprofiler2xbmc/open_cache_extension.rb