Module: Ratonvirus::Support::Backend

Included in:
Ratonvirus
Defined in:
lib/ratonvirus/support/backend.rb

Overview

The backend implementation allows us to set different backends on the main Ratonvirus configuration, e.g. scanner and storage backends. This makes the library agnostic of the actual implementation of these both and allows the developer to configure

The solution is a bit hacky monkey patch type of solution as it adds code to the underlying implementation through class_eval. The reason for this is to define arbitrary getter, setter and destroye methods that are nicer to use for the user. Wrapping this functionality to its own module makes the resulting code less prone to errors as all of the backends are defined exactly the same way.

Modifying this may be tough, so be sure to test properly in case you make any modifications.

Instance Method Summary collapse

Instance Method Details

#backend_class(backend_cls, backend_type) ⇒ Object

First argument “backend_cls”:

The subclass that refers to the backend's namespace, e.g.
`"Scanner"`.

Second argument “backend_type”:

The backend type in the given namespace, e.g. `:eicar`

The returned result will be e.g.

Ratonvirus::Scanner::Eicar
Ratonvirus::Storage::ActiveStorage


30
31
32
33
34
35
36
37
# File 'lib/ratonvirus/support/backend.rb', line 30

def backend_class(backend_cls, backend_type)
  return backend_type if backend_type.is_a?(Class)

  subclass = ActiveSupport::Inflector.camelize(backend_type.to_s)
  ActiveSupport::Inflector.constantize(
    "#{name}::#{backend_cls}::#{subclass}"
  )
end