Class: CDNGet::Base
- Inherits:
-
Object
- Object
- CDNGet::Base
- Defined in:
- lib/cdnget.rb
Class Method Summary collapse
Instance Method Summary collapse
- #download(library, version, basedir = ".", quiet: false) ⇒ Object
- #find(library) ⇒ Object
- #get(library, version) ⇒ Object
- #list ⇒ Object
Class Method Details
.inherited(klass) ⇒ Object
34 35 36 |
# File 'lib/cdnget.rb', line 34 def self.inherited(klass) CLASSES << klass end |
Instance Method Details
#download(library, version, basedir = ".", quiet: false) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cdnget.rb', line 50 def download(library, version, basedir=".", quiet: false) validate(library, version) File.exist?(basedir) or raise CommandError.new("#{basedir}: not exist.") File.directory?(basedir) or raise CommandError.new("#{basedir}: not a directory.") target_dir = File.join(basedir, library, version) d = get(library, version) d[:files].each do |file| filepath = File.join(target_dir, file) dirpath = File.dirname(filepath) print "#{filepath} ..." unless quiet url = File.join(d[:baseurl], file) # not use URI.join! content = fetch(url) content = content.force_encoding('ascii-8bit') print " Done (#{format_integer(content.bytesize)} byte)" unless quiet FileUtils.mkdir_p(dirpath) unless File.exist?(dirpath) unchanged = File.exist?(filepath) && File.read(filepath, mode: 'rb') == content if unchanged print " (Unchanged)" unless quiet else File.open(filepath, 'wb') {|f| f.write(content) } end puts() unless quiet end nil end |
#find(library) ⇒ Object
42 43 44 |
# File 'lib/cdnget.rb', line 42 def find(library) raise NotImplementedError.new("#{self.class.name}#find(): not implemented yet.") end |
#get(library, version) ⇒ Object
46 47 48 |
# File 'lib/cdnget.rb', line 46 def get(library, version) raise NotImplementedError.new("#{self.class.name}#get(): not implemented yet.") end |
#list ⇒ Object
38 39 40 |
# File 'lib/cdnget.rb', line 38 def list() raise NotImplementedError.new("#{self.class.name}#list(): not implemented yet.") end |