Class: AsProject::RemoteLibraryTask
- Inherits:
-
RemoteFileLoader
- Object
- Rake::TaskLib
- RemoteFileLoader
- AsProject::RemoteLibraryTask
- Defined in:
- lib/tasks/remote_library_task.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #define ⇒ Object
- #fetch_remote_library ⇒ Object
- #get_remote_file(url, target) ⇒ Object
-
#initialize(name) {|_self| ... } ⇒ RemoteLibraryTask
constructor
A new instance of RemoteLibraryTask.
- #swc_path ⇒ Object
Methods inherited from RemoteFileLoader
#fetch, #is_dmg?, #is_exe?, #is_gzip?, #is_swc?, #is_targz?, #is_zip?, #unpack_dmg, #unpack_downloaded_file, #unpack_targz, #unpack_zip
Constructor Details
#initialize(name) {|_self| ... } ⇒ RemoteLibraryTask
Returns a new instance of RemoteLibraryTask.
11 12 13 14 15 16 17 18 |
# File 'lib/tasks/remote_library_task.rb', line 11 def initialize(name) @name = name @path = File.join('lib', @name.to_s) @path_finder = PathFinder.new yield self if block_given? define end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/tasks/remote_library_task.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/tasks/remote_library_task.rb', line 7 def path @path end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/tasks/remote_library_task.rb', line 8 def url @url end |
Instance Method Details
#define ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tasks/remote_library_task.rb', line 20 def define if(url.nil?) puts 'RemoteLibraryTask ' + name.to_s + ' needs a url.' return end if(is_swc?(url)) @path = swc_path end file path do fetch_remote_library end task name => path end |
#fetch_remote_library ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tasks/remote_library_task.rb', line 36 def fetch_remote_library uri = URI.parse(url) parts = uri.path.split('/') if(parts[0] = '') parts.shift end remote_file_path = uri.host + '.' + parts.join('.') download_path = File.join(@path_finder.lib_downloads, @name.to_s, remote_file_path) if(!File.exists?(download_path)) puts ">> Fetching #{name.to_s} from #{url}" get_remote_file(url, download_path) end puts ">> Unpacking #{name.to_s} to #{path}" FileUtils.makedirs(path) if(is_zip?(download_path)) unpack_zip(download_path, path) elsif(is_swc?(download_path)) FileUtils.cp(download_path, path) end end |
#get_remote_file(url, target) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/tasks/remote_library_task.rb', line 60 def get_remote_file(url, target) response = fetch(url) File.makedirs(File.dirname(target)) # Store the downloaded file on disk File.open(target, 'wb') do |f| f.write(response.body) end end |
#swc_path ⇒ Object
70 71 72 73 |
# File 'lib/tasks/remote_library_task.rb', line 70 def swc_path swc = url.split('/').pop return File.join('lib', 'swcs', swc) end |