module Blueprinter::EmptyTypes

Private Instance Methods

use_default_value?(value, empty_type) click to toggle source
# File lib/blueprinter/empty_types.rb, line 12
def use_default_value?(value, empty_type)
  return value.nil? unless empty_type

  case empty_type
  when Blueprinter::EMPTY_COLLECTION
    array_like?(value) && value.empty?
  when Blueprinter::EMPTY_HASH
    value.is_a?(Hash) && value.empty?
  when Blueprinter::EMPTY_STRING
    value.to_s == ""
  else
    Blueprinter::Deprecation.report(
      "Invalid empty type '#{empty_type}' received. Blueprinter will raise an error in the next major version."\
      "Must be one of [nil, Blueprinter::EMPTY_COLLECTION, Blueprinter::EMPTY_HASH, Blueprinter::EMPTY_STRING]"
    )
  end
end