Class: Serega::SeregaPlugins::Formatters::CheckFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/plugins/formatters/formatters.rb

Overview

Validator for formatters defined as config options or directly as attribute :format option

Class Method Summary collapse

Class Method Details

.call(formatter_name, formatter) ⇒ void

This method returns an undefined value.

Check formatter type and parameters

Parameters:

  • formatter_name (Symbol)

    Name of formatter

  • formatter (#call)

    Formatter callable object

Raises:



241
242
243
244
245
246
247
248
249
250
# File 'lib/serega/plugins/formatters/formatters.rb', line 241

def call(formatter_name, formatter)
  raise Serega::SeregaError, "Option #{formatter_name.inspect} must have callable value" unless formatter.respond_to?(:call)

  SeregaValidations::Utils::CheckExtraKeywordArg.call(formatter, "#{formatter_name.inspect} value")
  params_count = SeregaUtils::ParamsCount.call(formatter, max_count: 2)

  if params_count > 2
    raise SeregaError, "Formatter can have maximum 2 parameters (value to format, context)"
  end
end