Module: Shibkit::MetaMeta::Mixin::CachedDownloads

Included in:
Logo, Source
Defined in:
lib/shibkit/meta_meta/mixin/cached_downloads.rb

Overview

A few simple utility functions for slurping data from XML

Defined Under Namespace

Modules: CDClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object

Automatically add class methods to the including class



38
39
40
41
42
# File 'lib/shibkit/meta_meta/mixin/cached_downloads.rb', line 38

def self.included(receiver)

  receiver.extend(CDClassMethods)

end

Instance Method Details

#fetch_local(filename) ⇒ Object

Copy a filesystem file into the working directory (slower but safer)



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/shibkit/meta_meta/mixin/cached_downloads.rb', line 45

def fetch_local(filename)
  
  return unless filename
  
  file_path = ::File.expand_path(filename)
  raise "Can't access file #{file_path}!" unless ::File.exists?(file_path) and
    ::File.readable?(file_path)

  file = Tempfile.new(Time.new.to_i.to_s) 
  open(file_path, 'w') { |f| f << http_response.to_s }

  return file

end

#fetch_remote(url) ⇒ Object

Copy a remote file into the working directory, also caching it for next update



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/shibkit/meta_meta/mixin/cached_downloads.rb', line 61

def fetch_remote(url)

  self.class.init_caches 
 
  http_response = RestClient.get(url)

  file = Tempfile.new(Time.new.to_i.to_s)
  open(file.path, 'w') { |f| f << http_response.to_s }

  return file

end