Module: Match::Storage

Defined in:
match/lib/match/storage.rb,
match/lib/match/storage/interface.rb,
match/lib/match/storage/s3_storage.rb,
match/lib/match/storage/git_storage.rb,
match/lib/match/storage/google_cloud_storage.rb

Defined Under Namespace

Classes: GitStorage, GoogleCloudStorage, Interface, S3Storage

Class Method Summary collapse

Class Method Details

.backendsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'match/lib/match/storage.rb', line 9

def backends
  @backends ||= {
    "git" => lambda { |params|
      return Storage::GitStorage.configure(params)
    },
    "google_cloud" => lambda { |params|
      return Storage::GoogleCloudStorage.configure(params)
    },
    "s3" => lambda { |params|
      return Storage::S3Storage.configure(params)
    }
  }
end

.for_mode(storage_mode, params) ⇒ Object



38
39
40
41
42
43
# File 'match/lib/match/storage.rb', line 38

def for_mode(storage_mode, params)
  configurator = backends[storage_mode.to_s]
  return configurator.call(params) if configurator

  UI.user_error!("No storage backend for storage mode '#{storage_mode}'")
end

.register_backend(type: nil, storage_class: nil, &configurator) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'match/lib/match/storage.rb', line 23

def register_backend(type: nil, storage_class: nil, &configurator)
  UI.user_error!("No type specified for storage backend") if type.nil?

  normalized_name = type.to_s
  UI.message("Replacing Match::Encryption backend for type '#{normalized_name}'") if backends.include?(normalized_name)

  if configurator
    @backends[normalized_name] = configurator
  elsif storage_class
    @backends[normalized_name] = ->(params) { return storage_class.configure(params) }
  else
    UI.user_error!("Specify either a `storage_class` or a configuration block when registering a storage backend")
  end
end