Class: ActiveRecord::Type::Registration

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

Direct Known Subclasses

DecorationRegistration

Instance Method Summary collapse

Constructor Details

#initialize(name, block, adapter: nil, override: nil) ⇒ Registration

Returns a new instance of Registration.



26
27
28
29
30
31
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 26

def initialize(name, block, adapter: nil, override: nil)
  @name = name
  @block = block
  @adapter = adapter
  @override = override
end

Instance Method Details

#<=>(other) ⇒ Object



45
46
47
48
49
50
51
52
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 45

def <=>(other)
  if conflicts_with?(other)
    raise TypeConflictError.new("Type #{name} was registered for all
                                adapters, but shadows a native type with
                                the same name for #{other.adapter}".squish)
  end
  priority <=> other.priority
end

#call(_registry, *args, adapter: nil, **kwargs) ⇒ Object



33
34
35
36
37
38
39
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 33

def call(_registry, *args, adapter: nil, **kwargs)
  if kwargs.any? # https://bugs.ruby-lang.org/issues/10856
    block.call(*args, **kwargs)
  else
    block.call(*args)
  end
end

#matches?(type_name, *args, **kwargs) ⇒ Boolean

Returns:



41
42
43
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 41

def matches?(type_name, *args, **kwargs)
  type_name == name && matches_adapter?(**kwargs)
end