Class: ActiveRecord::Type::AdapterSpecificRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/type/adapter_specific_registry.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeAdapterSpecificRegistry

Returns a new instance of AdapterSpecificRegistry.



9
10
11
# File 'lib/active_record/type/adapter_specific_registry.rb', line 9

def initialize
  @registrations = []
end

Instance Method Details

#add_modifier(options, klass, **args) ⇒ Object



18
19
20
# File 'lib/active_record/type/adapter_specific_registry.rb', line 18

def add_modifier(options, klass, **args)
  registrations << DecorationRegistration.new(options, klass, **args)
end

#initialize_copy(other) ⇒ Object



13
14
15
16
# File 'lib/active_record/type/adapter_specific_registry.rb', line 13

def initialize_copy(other)
  @registrations = @registrations.dup
  super
end

#lookup(symbol, *args, **kwargs) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/active_record/type/adapter_specific_registry.rb', line 30

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

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

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



22
23
24
25
26
27
28
# File 'lib/active_record/type/adapter_specific_registry.rb', line 22

def register(type_name, klass = nil, **options, &block)
  unless block_given?
    block = proc { |_, *args| klass.new(*args) }
    block.ruby2_keywords if block.respond_to?(:ruby2_keywords)
  end
  registrations << Registration.new(type_name, block, **options)
end