Class: ActiveRecordEncryption::Encryptor::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_encryption/encryptor/registry.rb

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



6
7
8
# File 'lib/active_record_encryption/encryptor/registry.rb', line 6

def initialize
  @registrations = []
end

Instance Method Details

#lookup(symbol, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/active_record_encryption/encryptor/registry.rb', line 15

def lookup(symbol, *args)
  registration = find_registration(symbol, *args)

  if registration
    registration.call(self, symbol, *args)
  else
    raise ArgumentError, "Unknown encryptor #{symbol.inspect}"
  end
end

#register(encryptor_name, klass = nil, **options, &block) ⇒ Object



10
11
12
13
# File 'lib/active_record_encryption/encryptor/registry.rb', line 10

def register(encryptor_name, klass = nil, **options, &block)
  block ||= proc { |_, *args| klass.new(*args) }
  registrations << Registration.new(encryptor_name, block, **options)
end