Module: Shale::Mapping::Validator

Defined in:
lib/shale/mapping/validator.rb

Class Method Summary collapse

Class Method Details

.validate_arguments(key, to, receiver, using) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Validate correctness of argument passed to map functions

Parameters:

  • key (String)
  • to (Symbol, nil)
  • receiver (Symbol, nil)
  • using (Hash, nil)

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shale/mapping/validator.rb', line 18

def self.validate_arguments(key, to, receiver, using)
  if to.nil? && using.nil?
    msg = ":to or :using argument is required for mapping '#{key}'"
    raise IncorrectMappingArgumentsError, msg
  end

  if to.nil? && !receiver.nil?
    msg = ":receiver argument for mapping '#{key}' " \
          'can only be used together with :to argument'
    raise IncorrectMappingArgumentsError, msg
  end

  if !using.nil? && (using[:from].nil? || using[:to].nil?)
    msg = ":using argument for mapping '#{key}' requires :to and :from keys"
    raise IncorrectMappingArgumentsError, msg
  end
end

.validate_namespace(key, namespace, prefix) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Validate correctness of namespace arguments

Parameters:

  • key (String)
  • namespace (String, Symbol, nil)
  • prefix (String, Symbol, nil)

Raises:



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/shale/mapping/validator.rb', line 45

def self.validate_namespace(key, namespace, prefix)
  return if namespace == :undefined && prefix == :undefined

  nsp = namespace == :undefined ? nil : namespace
  pfx = prefix == :undefined ? nil : prefix

  if (nsp && !pfx) || (!nsp && pfx)
    msg = "both :namespace and :prefix arguments are required for mapping '#{key}'"
    raise IncorrectMappingArgumentsError, msg
  end
end