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.


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

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

Instance Method Details

#<=>(other) ⇒ Object


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

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


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

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:


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

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