class StaticFM::Installer

Attributes

compressed[RW]
destination[RW]

Public Class Methods

download(asset_name, destination, opts = {}) click to toggle source
# File lib/static_fm/installer.rb, line 8
def self.download(asset_name, destination, opts = {})
  Installer.new(Asset.find(asset_name), destination, opts).download
end
new(asset, destination, opts = {}) click to toggle source
# File lib/static_fm/installer.rb, line 14
def initialize(asset, destination, opts = {})
  @asset = asset
  @destination  = destination || '.'
  @compressed   = opts[:compressed]
end

Public Instance Methods

compressed?() click to toggle source
# File lib/static_fm/installer.rb, line 40
def compressed?
  !!@compressed
end
download() click to toggle source
# File lib/static_fm/installer.rb, line 20
def download
  Logger.info "download\t#{@asset.display_name}"
  request = Typhoeus::Request.new(url, :max_redirects => 1, :follow_location => true)
  request.on_complete do |resp|
    File.open(file_name, "w+") { |file|
      file.write(resp.body)
      Logger.info "complete\t#{@asset.display_name} #{file_name}"
     }
  end

  hydra = Typhoeus::Hydra.new
  hydra.queue request
  hydra.run
end
file_name() click to toggle source
# File lib/static_fm/installer.rb, line 44
def file_name
  if File.directory?(@destination)
    File.join(@destination, @asset.file_name)
  else
    @destination
  end
end
url() click to toggle source
# File lib/static_fm/installer.rb, line 35
def url
  # @asset.url_with_options(options)
  @asset.url_with_options({ :compress => compressed? })
end