Class: S3Tree::Directory
- Inherits:
-
Object
- Object
- S3Tree::Directory
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- lib/s3_tree/directory.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #children ⇒ Object
- #files ⇒ Object
-
#initialize(bucket, path) ⇒ Directory
constructor
A new instance of Directory.
- #last_modified ⇒ Object
- #name ⇒ Object
- #parent ⇒ Object
- #size ⇒ Object
- #subdirectories ⇒ Object
Constructor Details
#initialize(bucket, path) ⇒ Directory
Returns a new instance of Directory.
6 7 8 9 |
# File 'lib/s3_tree/directory.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/directory.rb', line 4 def path @path end |
Instance Method Details
#children ⇒ Object
20 21 22 |
# File 'lib/s3_tree/directory.rb', line 20 def children subdirectories + files end |
#files ⇒ Object
30 31 32 33 34 35 |
# File 'lib/s3_tree/directory.rb', line 30 def files @files ||= list_objects['contents'].collect do |object| S3Tree::File.new(@bucket, s3_object: object) unless object.key.ends_with?('/') end.compact (@files.sort_by &:last_modified).reverse! end |
#last_modified ⇒ Object
41 42 43 |
# File 'lib/s3_tree/directory.rb', line 41 def last_modified (@bucket.objects(prefix: @path.gsub('+', ' ')).inject([]) { |date, s3_object| date.push(s3_object.last_modified) }).max end |
#name ⇒ Object
11 12 13 |
# File 'lib/s3_tree/directory.rb', line 11 def name URI.decode(path_pieces.last).gsub('+', ' ') end |
#parent ⇒ Object
15 16 17 18 |
# File 'lib/s3_tree/directory.rb', line 15 def parent parent_path = path_pieces[0..-2].join('/') S3Tree::Directory.new(@bucket, parent_path) unless parent_path.blank? end |
#size ⇒ Object
37 38 39 |
# File 'lib/s3_tree/directory.rb', line 37 def size number_to_human_size(@bucket.objects(prefix: @path.gsub('+', ' ')).inject(0) { |sum, s3_object| sum + s3_object.content_length }) end |