123456789_123456789_123456789_123456789_123456789_

Class: ActiveModel::Type::Registry

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activemodel/lib/active_model/type/registry.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newRegistry

[ GitHub ]

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

def initialize
  @registrations = {}
end

Instance Attribute Details

#registrations (readonly, private)

[ GitHub ]

  
# File 'activemodel/lib/active_model/type/registry.rb', line 34

attr_reader :registrations

Instance Method Details

#initialize_copy(other)

[ GitHub ]

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

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

#lookup(symbol)

[ GitHub ]

  
# File 'activemodel/lib/active_model/type/registry.rb', line 23

def lookup(symbol, ...)
  registration = registrations[symbol]

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

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

[ GitHub ]

  
# 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