Class: Valkyrie::Storage::Disk::BucketedStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/storage/disk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path:) ⇒ BucketedStorage

Returns a new instance of BucketedStorage.



98
99
100
# File 'lib/valkyrie/storage/disk.rb', line 98

def initialize(base_path:)
  @base_path = base_path
end

Instance Attribute Details

#base_path ⇒ Object (readonly)

Returns the value of attribute base_path.



97
98
99
# File 'lib/valkyrie/storage/disk.rb', line 97

def base_path
  @base_path
end

Instance Method Details

#bucketed_path(id) ⇒ Object



107
108
109
110
# File 'lib/valkyrie/storage/disk.rb', line 107

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

Raises:

  • (ArgumentError)


102
103
104
105
# File 'lib/valkyrie/storage/disk.rb', line 102

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