Class: DuckRecord::Type::Registration

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

Direct Known Subclasses

DecorationRegistration

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Registration.



25
26
27
28
29
# File 'lib/duck_record/type/registry.rb', line 25

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

Instance Method Details

#<=>(other) ⇒ Object



43
44
45
# File 'lib/duck_record/type/registry.rb', line 43

def <=>(other)
  priority <=> other.priority
end

#call(_registry, *args, **kwargs) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/duck_record/type/registry.rb', line 31

def call(_registry, *args, **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:



39
40
41
# File 'lib/duck_record/type/registry.rb', line 39

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