123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Type::Registration

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: activerecord/lib/active_record/type/adapter_specific_registry.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name, block, adapter: nil, override: nil) ⇒ Registration

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 48

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

Instance Attribute Details

#adapter (readonly, protected)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 73

attr_reader :name, :block, :adapter, :override

#block (readonly, protected)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 73

attr_reader :name, :block, :adapter, :override

#name (readonly, protected)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 73

attr_reader :name, :block, :adapter, :override

#override (readonly, protected)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 73

attr_reader :name, :block, :adapter, :override

Instance Method Details

#<=>(other)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 63

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)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 55

def call(_registry, *args, adapter: nil, **kwargs)
  block.call(*args, **kwargs)
end

#conflicts_with?(other) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 95

def conflicts_with?(other)
  same_priority_except_adapter?(other) &&
    has_adapter_conflict?(other)
end

#has_adapter_conflict?(other) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 104

def has_adapter_conflict?(other)
  (override.nil? && other.adapter) ||
    (adapter && other.override.nil?)
end

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

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 59

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

#matches_adapter?(adapter: nil) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 91

def matches_adapter?(adapter: nil, **)
  (self.adapter.nil? || adapter == self.adapter)
end

#priority (protected)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 75

def priority
  result = 0
  if adapter
    result |= 1
  end
  if override
    result |= 2
  end
  result
end

#priority_except_adapter (protected)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 86

def priority_except_adapter
  priority & 0b111111100
end

#same_priority_except_adapter?(other) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/type/adapter_specific_registry.rb', line 100

def same_priority_except_adapter?(other)
  priority_except_adapter == other.priority_except_adapter
end