Module: Shrine::Plugins::StorageFromConfig::ClassMethods

Defined in:
lib/shrine/plugins/storage_from_config.rb

Instance Method Summary collapse

Instance Method Details

#find_storage(name) ⇒ Object



14
15
16
# File 'lib/shrine/plugins/storage_from_config.rb', line 14

def find_storage(name)
  storage_from_config(name) || super
end

#storage_from_config(name) ⇒ Object (private)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/shrine/plugins/storage_from_config.rb', line 20

def storage_from_config(name)
  config = opts[:storage_settings]
  @storage_from_config ||= {}
  @storage_from_config[name.to_sym] ||=
    case config.type
    when 'memory'
      Shrine::Storage::Memory.new
    when 'local'
      Shrine::Storage::FileSystem.new('tmp', prefix: File.join('uploads', config.path.to_s, name.to_s))
    when 's3'
      sanitized_config = config.to_h.delete_if { |k, _| %i[type path upload_options].include?(k) }
      Shrine::Storage::S3.new(
        bucket: config.bucket,
        prefix: File.join(config.path.to_s, name.to_s),
        upload_options: config[:upload_options],
        **sanitized_config
      )
    end
end