Sha256: 63133e481d1a71de3832131ea735c2e94bbdafe92c2322703755dbc4046a11c3

Contents?: true

Size: 563 Bytes

Versions: 7

Compression:

Stored size: 563 Bytes

Contents

# Provides coercion and validation for the "inner" type of enums and arrays.
module Taro::Types::Shared::ItemType
  attr_reader :item_type

  def item_type=(new_type)
    item_type.nil? || new_type == item_type || raise_mixed_types(new_type)
    @item_type = new_type
  end
  alias_method :derive_from, :item_type=

  def raise_mixed_types(new_type)
    raise Taro::ArgumentError, <<~MSG
      All items must be of the same type. Mixed types are not supported for now.
      Expected another #{item_type} item but got a #{new_type} for #{self}.
    MSG
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
taro-2.3.0 lib/taro/types/shared/item_type.rb
taro-2.2.0 lib/taro/types/shared/item_type.rb
taro-2.1.0 lib/taro/types/shared/item_type.rb
taro-2.0.0 lib/taro/types/shared/item_type.rb
taro-1.4.0 lib/taro/types/shared/item_type.rb
taro-1.3.0 lib/taro/types/shared/item_type.rb
taro-1.2.0 lib/taro/types/shared/item_type.rb