Class: RestFtpDaemon::Location
- Inherits:
-
Object
- Object
- RestFtpDaemon::Location
- Includes:
- CommonHelpers
- Defined in:
- lib/rest-ftp-daemon/location.rb
Instance Attribute Summary collapse
-
#aws_bucket ⇒ Object
readonly
Returns the value of attribute aws_bucket.
-
#aws_id ⇒ Object
readonly
Returns the value of attribute aws_id.
-
#aws_region ⇒ Object
readonly
Returns the value of attribute aws_region.
-
#aws_secret ⇒ Object
readonly
Returns the value of attribute aws_secret.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#name ⇒ Object
Accessors.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #generate_temp_name! ⇒ Object
-
#initialize(original) ⇒ Location
constructor
A new instance of Location.
- #is?(kind) ⇒ Boolean
- #path ⇒ Object (also: #to_s)
- #scan_files ⇒ Object
- #size ⇒ Object
Methods included from CommonHelpers
#dashboard_url, #exception_to_error, #format_bytes, #identifier, #underscore
Constructor Details
#initialize(original) ⇒ Location
Returns a new instance of Location.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rest-ftp-daemon/location.rb', line 29 def initialize original # Strip spaces before/after, copying original "path" at the same time @original = original location_uri = original.strip # Replace tokens, fix scheme for local paths resolve_tokens! location_uri fix_scheme! location_uri # Ensure result does not contain tokens after replacement detected_tokens = detect_tokens(location_uri) unless detected_tokens.empty? raise RestFtpDaemon::UnresolvedTokens, detected_tokens.join(' ') end # Parse URL and do specific initializations parse_url location_uri case @uri when URI::FILE then init_file when URI::S3 then init_aws # Match AWS URL with BUCKET.s3.amazonaws.com end # Check that scheme is supported unless @uri.scheme raise RestFtpDaemon::UnsupportedScheme, url end end |
Instance Attribute Details
#aws_bucket ⇒ Object (readonly)
Returns the value of attribute aws_bucket.
17 18 19 |
# File 'lib/rest-ftp-daemon/location.rb', line 17 def aws_bucket @aws_bucket end |
#aws_id ⇒ Object (readonly)
Returns the value of attribute aws_id.
18 19 20 |
# File 'lib/rest-ftp-daemon/location.rb', line 18 def aws_id @aws_id end |
#aws_region ⇒ Object (readonly)
Returns the value of attribute aws_region.
16 17 18 |
# File 'lib/rest-ftp-daemon/location.rb', line 16 def aws_region @aws_region end |
#aws_secret ⇒ Object (readonly)
Returns the value of attribute aws_secret.
19 20 21 |
# File 'lib/rest-ftp-daemon/location.rb', line 19 def aws_secret @aws_secret end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
14 15 16 |
# File 'lib/rest-ftp-daemon/location.rb', line 14 def dir @dir end |
#name ⇒ Object
Accessors
9 10 11 |
# File 'lib/rest-ftp-daemon/location.rb', line 9 def name @name end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
11 12 13 |
# File 'lib/rest-ftp-daemon/location.rb', line 11 def original @original end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
13 14 15 |
# File 'lib/rest-ftp-daemon/location.rb', line 13 def scheme @scheme end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/rest-ftp-daemon/location.rb', line 12 def uri @uri end |
Instance Method Details
#generate_temp_name! ⇒ Object
83 84 85 |
# File 'lib/rest-ftp-daemon/location.rb', line 83 def generate_temp_name! @name = "#{@name}.temp-#{identifier(JOB_TEMPFILE_LEN)}" end |
#is?(kind) ⇒ Boolean
57 58 59 |
# File 'lib/rest-ftp-daemon/location.rb', line 57 def is? kind @uri.is_a? kind end |
#path ⇒ Object Also known as: to_s
61 62 63 64 |
# File 'lib/rest-ftp-daemon/location.rb', line 61 def path return @name if @dir.nil? File.join(@dir.to_s, @name.to_s) end |
#scan_files ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/rest-ftp-daemon/location.rb', line 67 def scan_files Dir.glob(path).collect do |file| next unless File.readable? file next unless File.file? file # Create a new location object self.class.new(file) end end |