Class: ActiveModel::Type::Registration

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

Instance Method Summary collapse

Constructor Details

#initialize(name, block) ⇒ Registration

Options must be taken because of bugs.ruby-lang.org/issues/10856


41
42
43
44
# File 'activemodel/lib/active_model/type/registry.rb', line 41

def initialize(name, block, **)
  @name = name
  @block = block
end

Instance Method Details

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


46
47
48
49
50
51
52
# File 'activemodel/lib/active_model/type/registry.rb', line 46

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


54
55
56
# File 'activemodel/lib/active_model/type/registry.rb', line 54

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