Class: ActiveModel::Type::Registry

Inherits:
Object
  • Object
show all
Defined in:
activemodel/lib/active_model/type/registry.rb

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.


5
6
7
# File 'activemodel/lib/active_model/type/registry.rb', line 5

def initialize
  @registrations = []
end

Instance Method Details

#lookup(symbol, *args) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'activemodel/lib/active_model/type/registry.rb', line 14

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

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

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


9
10
11
12
# File 'activemodel/lib/active_model/type/registry.rb', line 9

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