Class: StaticFM::Installer
- Inherits:
-
Object
- Object
- StaticFM::Installer
- Defined in:
- lib/static_fm/installer.rb
Instance Attribute Summary collapse
-
#compressed ⇒ Object
Returns the value of attribute compressed.
-
#destination ⇒ Object
Returns the value of attribute destination.
Class Method Summary collapse
Instance Method Summary collapse
- #compressed? ⇒ Boolean
- #download ⇒ Object
- #file_name ⇒ Object
-
#initialize(asset, destination, opts = {}) ⇒ Installer
constructor
A new instance of Installer.
- #url ⇒ Object
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
#compressed ⇒ Object
Returns the value of attribute compressed.
12 13 14 |
# File 'lib/static_fm/installer.rb', line 12 def compressed @compressed end |
#destination ⇒ Object
Returns the value of attribute destination.
12 13 14 |
# File 'lib/static_fm/installer.rb', line 12 def destination @destination end |
Class Method Details
Instance Method Details
#compressed? ⇒ Boolean
40 41 42 |
# File 'lib/static_fm/installer.rb', line 40 def compressed? !!@compressed end |
#download ⇒ Object
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_name ⇒ Object
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 |
#url ⇒ Object
35 36 37 38 |
# File 'lib/static_fm/installer.rb', line 35 def url # @asset.url_with_options(options) @asset.({ :compress => compressed? }) end |