Module: LunchMoney::Validators

Includes:
Kernel
Included in:
Objects::Asset, Objects::Crypto, Objects::CryptoBase
Defined in:
lib/lunchmoney/validators.rb

Overview

module containing reusable methods for validating data objects

Instance Method Summary collapse

Instance Method Details

#validate_iso8601!(value) ⇒ String

Parameters:

  • value (String)

Returns:

  • (String)

Raises:



23
24
25
26
27
28
29
# File 'lib/lunchmoney/validators.rb', line 23

def validate_iso8601!(value)
  return value unless LunchMoney.validate_object_attributes?

  raise(InvalidObjectAttribute, "#{value} is not a valid ISO 8601 string") unless valid_iso8601_string?(value)

  value
end

#validate_one_of!(value, valid_values) ⇒ String

Parameters:

  • value (String)
  • valid_values (Array<String>)

Returns:

  • (String)


12
13
14
15
16
17
18
19
20
# File 'lib/lunchmoney/validators.rb', line 12

def validate_one_of!(value, valid_values)
  return value unless LunchMoney.validate_object_attributes?

  if valid_values.exclude?(value)
    raise(InvalidObjectAttribute, "#{value} is invalid, must be one of #{valid_values.join(", ")}")
  end

  value
end