Class: Hyrax::DerivativeBucketedStorage

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/derivative_bucketed_storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path:) ⇒ DerivativeBucketedStorage

Returns a new instance of DerivativeBucketedStorage.



8
9
10
# File 'app/services/hyrax/derivative_bucketed_storage.rb', line 8

def initialize(base_path:)
  @base_path = base_path
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



6
7
8
# File 'app/services/hyrax/derivative_bucketed_storage.rb', line 6

def base_path
  @base_path
end

Instance Method Details

#bucketed_path(id) ⇒ Object

rubocop:enable Lint/UnusedMethodArgument



19
20
21
22
23
# File 'app/services/hyrax/derivative_bucketed_storage.rb', line 19

def bucketed_path(id)
  # We want to use the same code the derivative process uses so that items end up
  # stored in the place we expect them.
  Hyrax::DerivativePath.new(id.to_s).pair_directory
end

#generate(resource:, file:, original_filename:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument

Raises:

  • (ArgumentError)


13
14
15
16
# File 'app/services/hyrax/derivative_bucketed_storage.rb', line 13

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