Class: RestFtpDaemon::Location

Inherits:
Object
  • Object
show all
Includes:
CommonHelpers
Defined in:
lib/rest-ftp-daemon/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommonHelpers

#dashboard_url, #exception_to_error, #format_bytes, #identifier, #underscore

Constructor Details

#initialize(url) ⇒ Location

Returns a new instance of Location.



26
27
28
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
# File 'lib/rest-ftp-daemon/location.rb', line 26

def initialize url
  # Check parameters
  # unless url.is_a? String
  #   raise RestFtpDaemon::AssertionFailed, "location/init/string: #{url.inspect}"
  # end   
  debug nil

  @url = url.clone
  debug :url, url
  @tokens = []

  # Detect tokens in string
  @tokens = detect_tokens(url)
  debug :tokens, @tokens.inspect

  # First resolve tokens
  resolve_tokens! url

  # Build URI from parameters
  build_uri url

  # Extract dir and name
  build_dir_name

  # Specific initializations
  case @uri
  when URI::S3    then init_aws               # Match AWS URL with BUCKET.s3.amazonaws.com
  end
end

Instance Attribute Details

#aws_bucketObject (readonly)

Returns the value of attribute aws_bucket.



18
19
20
# File 'lib/rest-ftp-daemon/location.rb', line 18

def aws_bucket
  @aws_bucket
end

#aws_idObject (readonly)

Returns the value of attribute aws_id.



19
20
21
# File 'lib/rest-ftp-daemon/location.rb', line 19

def aws_id
  @aws_id
end

#aws_regionObject (readonly)

Returns the value of attribute aws_region.



17
18
19
# File 'lib/rest-ftp-daemon/location.rb', line 17

def aws_region
  @aws_region
end

#aws_secretObject (readonly)

Returns the value of attribute aws_secret.



20
21
22
# File 'lib/rest-ftp-daemon/location.rb', line 20

def aws_secret
  @aws_secret
end

#dirObject (readonly)

Returns the value of attribute dir.



15
16
17
# File 'lib/rest-ftp-daemon/location.rb', line 15

def dir
  @dir
end

#nameObject

Accessors



9
10
11
# File 'lib/rest-ftp-daemon/location.rb', line 9

def name
  @name
end

#schemeObject (readonly)

Returns the value of attribute scheme.



14
15
16
# File 'lib/rest-ftp-daemon/location.rb', line 14

def scheme
  @scheme
end

#tokensObject (readonly)

Returns the value of attribute tokens.



13
14
15
# File 'lib/rest-ftp-daemon/location.rb', line 13

def tokens
  @tokens
end

#uriObject (readonly)

Returns the value of attribute uri.



12
13
14
# File 'lib/rest-ftp-daemon/location.rb', line 12

def uri
  @uri
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/rest-ftp-daemon/location.rb', line 11

def url
  @url
end

Instance Method Details

#dir_fsObject



67
68
69
# File 'lib/rest-ftp-daemon/location.rb', line 67

def dir_fs
  '/' + @dir
end

#generate_temp_name!Object



88
89
90
# File 'lib/rest-ftp-daemon/location.rb', line 88

def generate_temp_name!
  @name = "#{@name}.temp-#{identifier(JOB_TEMPFILE_LEN)}"
end

#is?(kind) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rest-ftp-daemon/location.rb', line 56

def is? kind
  @uri.is_a? kind
end

#local_filesObject



71
72
73
74
75
76
77
78
# File 'lib/rest-ftp-daemon/location.rb', line 71

def local_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

#pathObject



60
61
62
# File 'lib/rest-ftp-daemon/location.rb', line 60

def path
  File.join(@dir.to_s, name.to_s)
end

#path_fsObject



64
65
66
# File 'lib/rest-ftp-daemon/location.rb', line 64

def path_fs
  '/' + path
end

#sizeObject



80
81
82
83
84
85
86
# File 'lib/rest-ftp-daemon/location.rb', line 80

def size
  return unless uri.is_a? URI::FILE

  local_file_path = path_fs
  return unless File.exist? path_fs
  return File.size path_fs
end