Module: Saphyr::Asserts::BaseAssert Private

Included in:
Fields::FieldBase
Defined in:
lib/saphyr/asserts/base_assert.rb

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

Instance Method Summary collapse

Instance Method Details

#assert_boolean(value) ⇒ 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.



5
6
7
# File 'lib/saphyr/asserts/base_assert.rb', line 5

def assert_boolean value
  value.is_a? TrueClass or value.is_a? FalseClass
end

#assert_class(klass, value, errors, error_code = Fields::FieldBase::ERR_TYPE) ⇒ 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.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/saphyr/asserts/base_assert.rb', line 9

def assert_class(klass, value, errors, error_code=Fields::FieldBase::ERR_TYPE)
  klass = [klass] unless klass.is_a? Array
  test = false
  klass.each do |k|
    if value.is_a? k; test = true; break; end
  end
  unless test
    errors << {
      type: err(error_code),
      data: {
        type: klass.to_s,
        got: value.class.name,
      }
    }
  end
  test
end

#assert_eq(opt_value, value, errors, error_code = Fields::FieldBase::ERR_EQ) ⇒ 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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/saphyr/asserts/base_assert.rb', line 27

def assert_eq(opt_value, value, errors, error_code=Fields::FieldBase::ERR_EQ)
  return nil if opt_value.nil?
  unless value == opt_value
    errors << {
      type: err(error_code),
      data: {
        _val: value,
        eq: opt_value,
      }
    }
    return false
  end
  true
end

#assert_in(opt_values, value, errors, error_code = Fields::FieldBase::ERR_IN) ⇒ 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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/saphyr/asserts/base_assert.rb', line 42

def assert_in(opt_values, value, errors, error_code=Fields::FieldBase::ERR_IN)
  return nil if opt_values.nil?
  unless opt_values.include? value
    errors << {
      type: err(error_code),
      data: {
        _val: value,
        in: opt_values,
      }
    }
    return false
  end
  true
end

#assert_not_empty(value, errors, error_code = Fields::FieldBase::ERR_NOT_EMPTY) ⇒ 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.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/saphyr/asserts/base_assert.rb', line 57

def assert_not_empty(value, errors, error_code=Fields::FieldBase::ERR_NOT_EMPTY)
  if value.empty?
    errors << {
      type: err(error_code),
      data: {
        _val: value,
      }
    }
    return false
  end
  true
end