Class: Valkyrie::Storage::Disk::BucketedStorage
- Inherits:
-
Object
- Object
- Valkyrie::Storage::Disk::BucketedStorage
- Defined in:
- lib/valkyrie/storage/disk.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
Instance Method Summary collapse
- #bucketed_path(id) ⇒ Object
- #generate(resource:, file:, original_filename:) ⇒ Object
-
#initialize(base_path:) ⇒ BucketedStorage
constructor
A new instance of BucketedStorage.
Constructor Details
#initialize(base_path:) ⇒ BucketedStorage
Returns a new instance of BucketedStorage.
52 53 54 |
# File 'lib/valkyrie/storage/disk.rb', line 52 def initialize(base_path:) @base_path = base_path end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
51 52 53 |
# File 'lib/valkyrie/storage/disk.rb', line 51 def base_path @base_path end |
Instance Method Details
#bucketed_path(id) ⇒ Object
61 62 63 64 |
# File 'lib/valkyrie/storage/disk.rb', line 61 def bucketed_path(id) cleaned_id = id.to_s.delete("-") cleaned_id[0..5].chars.each_slice(2).map(&:join) + [cleaned_id] end |
#generate(resource:, file:, original_filename:) ⇒ Object
56 57 58 59 |
# File 'lib/valkyrie/storage/disk.rb', line 56 def generate(resource:, file:, original_filename:) raise ArgumentError, "original_filename must be provided" unless original_filename Pathname.new(base_path).join(*bucketed_path(resource.id)).join(original_filename) end |