Class: EacFs::CachedDownload
Instance Attribute Summary collapse
- 
  
    
      #fs_cache  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute fs_cache.
 - 
  
    
      #url  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute url.
 
Instance Method Summary collapse
- #assert ⇒ Object
 - #download ⇒ Object
 - 
  
    
      #initialize(url, parent_fs_cache = nil)  ⇒ CachedDownload 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of CachedDownload.
 - #path ⇒ Object
 
Constructor Details
#initialize(url, parent_fs_cache = nil) ⇒ CachedDownload
Returns a new instance of CachedDownload.
      11 12 13 14  | 
    
      # File 'lib/eac_fs/cached_download.rb', line 11 def initialize(url, parent_fs_cache = nil) @url = url @fs_cache = (parent_fs_cache || fs_cache).child(url.to_s.parameterize) end  | 
  
Instance Attribute Details
#fs_cache ⇒ Object (readonly)
Returns the value of attribute fs_cache.
      9 10 11  | 
    
      # File 'lib/eac_fs/cached_download.rb', line 9 def fs_cache @fs_cache end  | 
  
#url ⇒ Object (readonly)
Returns the value of attribute url.
      9 10 11  | 
    
      # File 'lib/eac_fs/cached_download.rb', line 9 def url @url end  | 
  
Instance Method Details
#assert ⇒ Object
      16 17 18  | 
    
      # File 'lib/eac_fs/cached_download.rb', line 16 def assert download unless fs_cache.stored? end  | 
  
#download ⇒ Object
      20 21 22 23 24 25 26  | 
    
      # File 'lib/eac_fs/cached_download.rb', line 20 def download ::EacRubyUtils::Fs::Temp.on_file do |temp| download_to(temp) fs_cache.content_path.to_pathname.dirname.mkpath ::FileUtils.mv(temp.to_path, fs_cache.content_path) end end  | 
  
#path ⇒ Object
      28 29 30  | 
    
      # File 'lib/eac_fs/cached_download.rb', line 28 def path fs_cache.content_path.to_pathname end  |