Class: ActiveModel::Type::Registry

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



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

def initialize
  @registrations = {}
end

Instance Method Details

#initialize_copy(other) ⇒ Object



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

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

#lookup(symbol, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'activemodel/lib/active_model/type/registry.rb', line 23

def lookup(symbol, *args)
  registration = registrations[symbol]

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

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



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

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