Module: Shrine::Plugins::ConfigurableStorage::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#configurable_storage_name(name) ⇒ Object



52
53
54
55
56
# File 'lib/shrine/plugins/configurable_storage.rb', line 52

def configurable_storage_name(name)
  name = name.to_sym
  @storage_name = name
  @memoized_storage.delete(name)
end

#find_storage(name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/shrine/plugins/configurable_storage.rb', line 58

def find_storage(name)
  return super unless @storage_name

  name = name.to_sym
  @memoized_storage.fetch(name) do
    group = ConfigurableStorage.fetch(@storage_name || :default) do
      ConfigurableStorage.fetch(:default) do
        raise_storage_not_configured(name)
      end
    end
    group[name] || super
  end
end

#raise_storage_not_configured(name) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/shrine/plugins/configurable_storage.rb', line 72

def raise_storage_not_configured(name)
  raise(
    StorageNotConfigured,
    format(
      "Uploader storage not set up for '%<storage_name>s'. " \
      "Make sure you setup the configurable storage: \n\n" \
      "Shrine::Plugins::ConfigurableStorage.configure do |config| \n" \
      "  config[:%<storage_key>s] = { \n"\
      "    cache: Shrine::Storage::..., \n"\
      "    store: Shrine::Storage::... \n"\
      "  }.freeze \n" \
      'end',
      storage_name: name,
      storage_key: @storage_name
    )
  )
end

#setupObject



47
48
49
50
# File 'lib/shrine/plugins/configurable_storage.rb', line 47

def setup
  @storage_name = nil
  @memoized_storage = {}
end