Class: StaticFM::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/static_fm/installer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asset, destination, opts = {}) ⇒ Installer

Returns a new instance of Installer.



14
15
16
17
18
# File 'lib/static_fm/installer.rb', line 14

def initialize(asset, destination, opts = {})
  @asset = asset
  @destination  = destination || '.'
  @compressed   = opts[:compressed]
end

Instance Attribute Details

#compressedObject

Returns the value of attribute compressed.



12
13
14
# File 'lib/static_fm/installer.rb', line 12

def compressed
  @compressed
end

#destinationObject

Returns the value of attribute destination.



12
13
14
# File 'lib/static_fm/installer.rb', line 12

def destination
  @destination
end

Class Method Details

.download(asset_name, destination, opts = {}) ⇒ Object



8
9
10
# 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

Instance Method Details

#compressed?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/static_fm/installer.rb', line 40

def compressed?
  !!@compressed
end

#downloadObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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_nameObject



44
45
46
47
48
49
50
# 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

#urlObject



35
36
37
38
# File 'lib/static_fm/installer.rb', line 35

def url
  # @asset.url_with_options(options)
  @asset.url_with_options({ :compress => compressed? })
end