Class: ActiveModel::Type::Registry

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

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



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

def initialize
  @registrations = []
end

Instance Method Details

#initialize_dup(other) ⇒ Object



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

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

#lookup(symbol, *args) ⇒ Object



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

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



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

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_klass.new(type_name, block, **options)
end