Sha256: 886b9bc2138e960a9bd120cd0ab4d15f18fccf8de75470a4e995aa712bf7befd

Contents?: true

Size: 1016 Bytes

Versions: 1

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

class ReeMapper::String < ReeMapper::AbstractType
  contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
  def serialize(value, name:, role: nil)
    if value.is_a? String
      value
    else
      raise ReeMapper::TypeError, "`#{name}` should be a string, got `#{truncate(value.inspect)}`"
    end
  end

  contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
  def cast(value, name:, role: nil)
    serialize(value, name: name, role: role)
  end

  contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
  def db_dump(value, name:, role: nil)
    serialize(value, name: name, role: role)
  end

  contract(Any, Kwargs[name: String, role: Nilor[Symbol, ArrayOf[Symbol]]] => String).throws(ReeMapper::TypeError)
  def db_load(value, name:, role: nil)
    serialize(value, name: name, role: role)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ree_lib-1.0.86 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/string.rb