Sha256: 814f1bdf4815f2796eb0da89cda122e3bc17f98fffc3adcd14c613c09eef4616

Contents?: true

Size: 1.63 KB

Versions: 17

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

class ReeMapper::Array < ReeMapper::AbstractType
  attr_reader :of

  contract ReeMapper::Field => Any
  def initialize(of)
    @of = of
  end

  contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
  def serialize(value, role: nil)
    if value.is_a?(Array)
      value.map {
        if _1.nil? && of.null
          _1
        else
          of.type.serialize(_1, role: role)
        end
      }
    else
      raise ReeMapper::TypeError, 'should be an array'
    end
  end

  contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
  def cast(value, role: nil)
    if value.is_a?(Array)
      value.map {
        if _1.nil? && of.null
          _1
        else
          of.type.cast(_1, role: role)
        end
      }
    else
      raise ReeMapper::TypeError, "should be an array"
    end
  end

  contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
  def db_dump(value, role: nil)
    if value.is_a?(Array)
      value.map {
        if _1.nil? && of.null
          _1
        else
          of.type.db_dump(_1, role: role)
        end
      }
    else
      raise ReeMapper::TypeError, 'should be an array'
    end
  end

  contract(Any, Kwargs[role: Nilor[Symbol, ArrayOf[Symbol]]] => Array).throws(ReeMapper::TypeError)
  def db_load(value, role: nil)
    if value.is_a?(Array)
      value.map {
        if _1.nil? && of.null
          _1
        else
          of.type.db_load(_1, role: role)
        end
      }
    else
      raise ReeMapper::TypeError, "should be an array"
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ree_lib-1.0.16 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.15 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.14 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.13 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.12 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.11 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.10 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.9 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.8 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.7 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.6 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.5 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.4 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.3 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.2 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.1 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb
ree_lib-1.0.0 lib/ree_lib/packages/ree_mapper/package/ree_mapper/types/array.rb