Class: S3Tree::File
- Inherits:
-
Object
- Object
- S3Tree::File
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- lib/s3_tree/file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #directory ⇒ Object
- #extension ⇒ Object
-
#initialize(bucket, path) ⇒ File
constructor
A new instance of File.
- #last_modified ⇒ Object
- #name ⇒ Object
- #s3_object ⇒ Object
- #size ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(bucket, path) ⇒ File
Returns a new instance of File.
6 7 8 9 |
# File 'lib/s3_tree/file.rb', line 6 def initialize(bucket, path) @bucket = bucket @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/s3_tree/file.rb', line 4 def path @path end |
Instance Method Details
#directory ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/s3_tree/file.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 |
#extension ⇒ Object
16 17 18 |
# File 'lib/s3_tree/file.rb', line 16 def extension @extension ||= File.extname(@path[:s3_object].key) end |
#last_modified ⇒ Object
32 33 34 |
# File 'lib/s3_tree/file.rb', line 32 def last_modified @path[:s3_object].last_modified end |
#name ⇒ Object
11 12 13 14 |
# File 'lib/s3_tree/file.rb', line 11 def name @name ||= File.basename(@path[:s3_object].key) URI.decode(@name).gsub('+', ' ') end |
#s3_object ⇒ Object
36 37 38 |
# File 'lib/s3_tree/file.rb', line 36 def s3_object @s3_object ||= @bucket.object(@path) end |
#size ⇒ Object
28 29 30 |
# File 'lib/s3_tree/file.rb', line 28 def size number_to_human_size(@path[:s3_object].size) end |
#url ⇒ Object
40 41 42 |
# File 'lib/s3_tree/file.rb', line 40 def url @bucket.object(URI.decode(@path[:s3_object].key).gsub('+', ' ')).presigned_url(:get) end |