Class: Typingpool::Project::Remote
- Inherits:
-
Object
- Object
- Typingpool::Project::Remote
- Defined in:
- lib/typingpool/project/remote.rb,
lib/typingpool/project/remote/s3.rb,
lib/typingpool/project/remote/sftp.rb
Overview
Representation of the Project instance on remote servers. This is basically a collection of audio files to be transcribed and HTML files containing instructions and a form for the transcribers. The backend can be Amazon S3 (the default) or an SFTP server. Each backend is encapsulated in its own subclass. A backend subclass must provide a ‘put’ method, which takes an array of IO streams and an optional array of remote file basenames; a ‘remove’ method, which takes an array of remote file basenames; and the methods ‘host’ and ‘path’, which return the location of the destination server and destination directory, respectively.
Thus, there will always be ‘put’, ‘remove’, ‘host’ and ‘path’ methods available, in addition to the Project::Remote methods outlined below.
Defined Under Namespace
Instance Attribute Summary collapse
-
#name ⇒ Object
The project name.
Class Method Summary collapse
-
.from_config(name, config) ⇒ Object
Constructor.
Instance Method Summary collapse
-
#file_to_url(file) ⇒ Object
Given a file path, returns the URL to the file path were it to be uploaded by this instance.
-
#remove_urls(urls) ⇒ Object
Like project.remote.remove, except it takes an array of URLs instead an array of remote basenames, saving you from having to manually extract basenames from the URL.
-
#url_basename(url) ⇒ Object
Given an URL, returns the file portion of the path, given the configuration of this instance.
Instance Attribute Details
#name ⇒ Object
The project name
23 24 25 |
# File 'lib/typingpool/project/remote.rb', line 23 def name @name end |
Class Method Details
.from_config(name, config) ⇒ Object
Constructor. Takes the project name and a Config instance. Returns a Project::Remote::S3 or Project::Remote::SFTP instance, depending on the particulars of the Config. If there are sufficient config params to return EITHER an S3 or SFTP subclass, it will prefer the SFTP subclass.
31 32 33 34 35 36 37 38 39 |
# File 'lib/typingpool/project/remote.rb', line 31 def self.from_config(name, config) if config.sftp SFTP.new(name, config.sftp) elsif config.amazon && config.amazon.bucket S3.new(name, config.amazon) else raise Error, "No valid upload params found in config file (SFTP or Amazon info)" end end |
Instance Method Details
#file_to_url(file) ⇒ Object
Given a file path, returns the URL to the file path were it to be uploaded by this instance.
51 52 53 |
# File 'lib/typingpool/project/remote.rb', line 51 def file_to_url(file) "#{@url}/#{URI.escape(file)}" end |
#remove_urls(urls) ⇒ Object
Like project.remote.remove, except it takes an array of URLs instead an array of remote basenames, saving you from having to manually extract basenames from the URL.
44 45 46 47 |
# File 'lib/typingpool/project/remote.rb', line 44 def remove_urls(urls) basenames = urls.map{|url| url_basename(url) } remove(basenames){|file| yield(file) if block_given? } end |
#url_basename(url) ⇒ Object
Given an URL, returns the file portion of the path, given the configuration of this instance.
57 58 59 60 |
# File 'lib/typingpool/project/remote.rb', line 57 def url_basename(url) basename = url.split("#{self.url}/")[1] or raise Error, "Could not find base url '#{self.url}' within longer url '#{url}'" URI.unescape(basename) end |