Class: ActiveRecord::Type::AdapterSpecificRegistry

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeAdapterSpecificRegistry

Returns a new instance of AdapterSpecificRegistry.



7
8
9
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 7

def initialize
  @registrations = []
end

Instance Method Details

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



15
16
17
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 15

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

#initialize_copy(other) ⇒ Object



11
12
13
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 11

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

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



27
28
29
30
31
32
33
34
35
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 27

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



19
20
21
22
23
24
25
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 19

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