Class: Sprout::RemoteFileTarget
- Inherits:
-
Object
- Object
- Sprout::RemoteFileTarget
- Defined in:
- lib/sprout/remote_file_target.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#archive_path ⇒ Object
Relative path within the archive to the executable or binary of interest.
-
#archive_type ⇒ Object
If the archive type cannot be assumed from the returned file name, it must be provided as one of the following: :exe :zip :targz :gzip :swc :rb :dmg.
-
#environment ⇒ Object
The string environment variable name to check before downloading anything.
-
#filename ⇒ Object
Filename for the downloaded file.
-
#gem_name ⇒ Object
Returns the value of attribute gem_name.
-
#gem_version ⇒ Object
Returns the value of attribute gem_version.
-
#install_path ⇒ Object
The user path where this gem will download and install files This value is set by the Sprout::Builder that creates this RemoteFileTarget.
-
#md5 ⇒ Object
Optional md5 hash, usually set in the sprout.spec for each RemoteFileTarget If this value is set, the downloaded archive will be hashed, the hashes will be compared and if they differ, the installation process will break.
-
#mount_path ⇒ Object
Used for dmg archives.
-
#platform ⇒ Object
Which platform will this RemoteFileTarget support.
-
#url ⇒ Object
URL where Sprouts can go to download the RemoteFileTarget archive.
Instance Method Summary collapse
-
#downloaded_path ⇒ Object
Parent directory where archives are downloaded can be something like: ~/Library/Sprouts/cache/0.7/sprout-somesprout-tool.x.x.x/.
- #downloaded_path=(path) ⇒ Object
-
#executable ⇒ Object
Return the basename of the executable that this RemoteFileTarget refers to.
-
#file_name(url = nil) ⇒ Object
Base file name represented by the provided
urlWill strip off any ? arguments and trailing slashes. -
#installed_path ⇒ Object
The root path to the unpacked archive files.
-
#resolve(update = false) ⇒ Object
Resolve this RemoteFileTarget now.
Instance Attribute Details
#archive_path ⇒ Object
Relative path within the archive to the executable or binary of interest
56 57 58 |
# File 'lib/sprout/remote_file_target.rb', line 56 def archive_path @archive_path ||= '' end |
#archive_type ⇒ Object
If the archive type cannot be assumed from the returned file name, it must be provided as one of the following:
:exe
:zip
:targz
:gzip
:swc
:rb
:dmg
50 51 52 |
# File 'lib/sprout/remote_file_target.rb', line 50 def archive_type @archive_type end |
#environment ⇒ Object
The string environment variable name to check before downloading anything.
15 16 17 |
# File 'lib/sprout/remote_file_target.rb', line 15 def environment @environment end |
#filename ⇒ Object
Filename for the downloaded file. Introduced to fix railsy URL issues.
53 54 55 |
# File 'lib/sprout/remote_file_target.rb', line 53 def filename @filename end |
#gem_name ⇒ Object
Returns the value of attribute gem_name.
9 10 11 |
# File 'lib/sprout/remote_file_target.rb', line 9 def gem_name @gem_name end |
#gem_version ⇒ Object
Returns the value of attribute gem_version.
10 11 12 |
# File 'lib/sprout/remote_file_target.rb', line 10 def gem_version @gem_version end |
#install_path ⇒ Object
The user path where this gem will download and install files This value is set by the Sprout::Builder that creates this RemoteFileTarget
19 20 21 |
# File 'lib/sprout/remote_file_target.rb', line 19 def install_path @install_path end |
#md5 ⇒ Object
Optional md5 hash, usually set in the sprout.spec for each RemoteFileTarget If this value is set, the downloaded archive will be hashed, the hashes will be compared and if they differ, the installation process will break.
24 25 26 |
# File 'lib/sprout/remote_file_target.rb', line 24 def md5 @md5 end |
#mount_path ⇒ Object
Used for dmg archives. Absolute path to the mounted dmg (essentially its name)
27 28 29 |
# File 'lib/sprout/remote_file_target.rb', line 27 def mount_path @mount_path end |
#platform ⇒ Object
Which platform will this RemoteFileTarget support. Supported options are:
* universal
* macosx
* win32
* linux
35 36 37 |
# File 'lib/sprout/remote_file_target.rb', line 35 def platform @platform end |
#url ⇒ Object
URL where Sprouts can go to download the RemoteFileTarget archive
38 39 40 |
# File 'lib/sprout/remote_file_target.rb', line 38 def url @url end |
Instance Method Details
#downloaded_path ⇒ Object
Parent directory where archives are downloaded can be something like: ~/Library/Sprouts/cache/0.7/sprout-somesprout-tool.x.x.x/
108 109 110 111 |
# File 'lib/sprout/remote_file_target.rb', line 108 def downloaded_path @downloaded_path ||= File.join(install_path, file_name(url)) return @downloaded_path end |
#downloaded_path=(path) ⇒ Object
102 103 104 |
# File 'lib/sprout/remote_file_target.rb', line 102 def downloaded_path=(path) @downloaded_path = path end |
#executable ⇒ Object
Return the basename of the executable that this RemoteFileTarget refers to
91 92 93 |
# File 'lib/sprout/remote_file_target.rb', line 91 def executable return File.basename(archive_path) end |
#file_name(url = nil) ⇒ Object
Base file name represented by the provided url Will strip off any ? arguments and trailing slashes. May not play nice with Rails URLS, We expect archive file name suffixes like, zip, gzip, tar.gz, dmg, etc.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/sprout/remote_file_target.rb', line 116 def file_name(url=nil) return @filename if(@filename) url ||= self.url url = url.split('?').shift parts = url.split('/') if(parts.last == '/') parts.pop end file = parts.pop if(!archive_type.nil? && file.match(/\.#{archive_type.to_s}$/).nil?) file << ".#{archive_type.to_s}" end return file end |
#installed_path ⇒ Object
The root path to the unpacked archive files. This is the base path that will be added to any archive_path relative paths
97 98 99 100 |
# File 'lib/sprout/remote_file_target.rb', line 97 def installed_path @installed_path ||= inferred_installed_path return @installed_path end |
#resolve(update = false) ⇒ Object
Resolve this RemoteFileTarget now. This method is called by the Sprout::Builder and will download, install and unpack the described archive, unless it is already installed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sprout/remote_file_target.rb', line 63 def resolve(update=false) # Wanted to raise, but it seems we support RemoteFileTargets that are actually self-installed binaries... # like SWFMill on Linux. @see the BuilderTest.test_build_no_install for more info. # raise RemoteFileTargetError.new('Cannot retrieve a RemoteFileTarget without a url') if url.nil? return if url.nil? if(filename) self.downloaded_path = File.join(File.dirname(downloaded_path), filename) end should_download = ( url && !File.exists?(installed_path) && !File.exists?(downloaded_path) ) if(should_download) content = download(url, update) FileUtils.makedirs(File.dirname(downloaded_path)) FileUtils.touch(downloaded_path) File.open(downloaded_path, 'rb+') do |file| file.write(content) end end if(!File.exists?(installed_path) && !File.exists?(File.join(installed_path, archive_path)) ) archive_root = File.join(install_path, 'archive') install(downloaded_path, archive_root, update, archive_type) end end |