Class: Saphyr::Fields::B64Field

Inherits:
FieldBase show all
Defined in:
lib/saphyr/fields/b64_field.rb

Overview

The B64 field type

Allowed options is: :strict (boolean)

When in strict mode (:strict == true):

  • Line breaks are not allowed

  • Padding must be correct

Not in strict mode (:strict == false):

  • Line breaks are allowed

  • Padding is not required

Constant Summary collapse

PREFIX =
'b64'
EXPECTED_TYPES =
String
AUTHORIZED_OPTIONS =

:strict = true / false

[:strict]
FORMAT_REGEXP =
/^(?:[A-Za-z0-9+\/]*[\r\n|\n]*)*(?:[=]{1,2})?$/

Constants inherited from FieldBase

FieldBase::DEFAULT_OPTS, FieldBase::DEFAULT_OPT_VALUES, FieldBase::EXCLUSIVE_OPTIONS, FieldBase::NOT_EQUALS_OPTIONS, FieldBase::NOT_SUP_OPTIONS, FieldBase::NOT_SUP_OR_EQUALS_OPTIONS, FieldBase::REQUIRED_ONE_OF_OPTIONS, FieldBase::REQUIRED_OPTIONS

Constants included from Asserts::ErrorConstants

Asserts::ErrorConstants::ERR_BAD_FORMAT, Asserts::ErrorConstants::ERR_EQ, Asserts::ErrorConstants::ERR_GT, Asserts::ErrorConstants::ERR_GTE, Asserts::ErrorConstants::ERR_IN, Asserts::ErrorConstants::ERR_LEN, Asserts::ErrorConstants::ERR_LT, Asserts::ErrorConstants::ERR_LTE, Asserts::ErrorConstants::ERR_MAX, Asserts::ErrorConstants::ERR_MIN, Asserts::ErrorConstants::ERR_NOT_EMPTY, Asserts::ErrorConstants::ERR_NOT_NULLABLE, Asserts::ErrorConstants::ERR_REGEXP, Asserts::ErrorConstants::ERR_SIZE_EQ, Asserts::ErrorConstants::ERR_SIZE_LEN, Asserts::ErrorConstants::ERR_SIZE_MAX, Asserts::ErrorConstants::ERR_SIZE_MIN, Asserts::ErrorConstants::ERR_TYPE

Instance Attribute Summary

Attributes inherited from FieldBase

#opts

Instance Method Summary collapse

Methods inherited from FieldBase

#authorized_options, #default?, #err, #exclusive_options, #expected_types, #not_equals_options, #not_sup_options, #not_sup_or_equals_options, #nullable?, #prefix, #required?, #required_one_of_options, #required_options, #validate

Methods included from Asserts::StringAssert

#assert_string_regexp

Methods included from Asserts::NumericAssert

#assert_numeric_gt, #assert_numeric_gte, #assert_numeric_lt, #assert_numeric_lte

Methods included from Asserts::SizeAssert

#assert_size_len, #assert_size_max, #assert_size_min

Methods included from Asserts::BaseAssert

#assert_boolean, #assert_class, #assert_eq, #assert_in, #assert_not_empty

Constructor Details

#initialize(opts = {}) ⇒ B64Field

Returns a new instance of B64Field.



25
26
27
28
29
30
31
32
33
34
# File 'lib/saphyr/fields/b64_field.rb', line 25

def initialize(opts={})
  if opts[:strict].nil?
    opts[:strict] = true
  else
    unless [true, false].include? opts[:strict]
      raise Saphyr::Error.new "Bad B64 strict option must be a boolean"
    end
  end
  super opts
end