Class: Rosette::Core::Validators::SerializerValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/rosette/core/validators/serializer_validator.rb

Overview

Validates a serializer by making sure the given repo has been configured to support it.

Examples:

v = SerializerValidator.new
v.valid?('yaml/rails', 'my_repo', config)  # => true
v.valid?('yaml/blarg', 'my_repo', config)  # => false
v.messages  # => ["Unable to find serializer 'yaml/blarg'."]

Instance Attribute Summary

Attributes inherited from Validator

#options

Instance Method Summary collapse

Methods inherited from Validator

#initialize, #messages

Constructor Details

This class inherits a constructor from Rosette::Core::Validators::Validator

Instance Method Details

#valid?(serializer_id, repo_name, configuration) ⇒ Boolean

Returns true if the serializer is valid, false otherwise.

Parameters:

  • serializer_id (String)

    The serializer to validate.

  • repo_name (String)

    The repo to use. This method checks the entry in configuration for repo_name to see if it supports serializer_id.

  • configuration (Configurator)

    The Rosette configuration to use.

Returns:

  • (Boolean)

24
25
26
27
28
29
30
31
32
# File 'lib/rosette/core/validators/serializer_validator.rb', line 24

def valid?(serializer_id, repo_name, configuration)
  repo = configuration.get_repo(repo_name)
  if repo.get_serializer_config(serializer_id)
    true
  else
    messages << "Unable to find serializer '#{serializer_id}'."
    false
  end
end