Class: S3Tree::Files

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper
Defined in:
lib/s3_tree/files.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, path) ⇒ Files

Returns a new instance of Files.



6
7
8
9
# File 'lib/s3_tree/files.rb', line 6

def initialize(bucket, path)
  @bucket = bucket
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/s3_tree/files.rb', line 4

def path
  @path
end

Instance Method Details

#directoryObject



20
21
22
23
24
25
26
# File 'lib/s3_tree/files.rb', line 20

def directory
  @directory ||= begin
    dir = File.dirname(@path[:s3_object].key)
    dir = nil if dir == '.'
    S3Tree::Directory.new(@bucket, dir)
  end
end

#extensionObject



16
17
18
# File 'lib/s3_tree/files.rb', line 16

def extension
  @extension ||= File.extname(@path[:s3_object].key)
end

#last_modifiedObject



32
33
34
# File 'lib/s3_tree/files.rb', line 32

def last_modified
  @path[:s3_object].last_modified
end

#nameObject



11
12
13
14
# File 'lib/s3_tree/files.rb', line 11

def name
  @name ||= File.basename(@path[:s3_object].key)
  URI.decode(@name).gsub('+', ' ')
end

#s3_objectObject



36
37
38
# File 'lib/s3_tree/files.rb', line 36

def s3_object
  @s3_object ||= @bucket.object(@path)
end

#sizeObject



28
29
30
# File 'lib/s3_tree/files.rb', line 28

def size
  number_to_human_size(@path[:s3_object].size)
end

#urlObject



40
41
42
# File 'lib/s3_tree/files.rb', line 40

def url
  @bucket.object(URI.decode(@path[:s3_object].key).gsub('+', ' ')).presigned_url(:get)
end