Sha256: f51044a9a1ffd2d3f4b70d6020077cad0564228c2d94c010e292796c1b912166

Contents?: true

Size: 543 Bytes

Versions: 2

Compression:

Stored size: 543 Bytes

Contents

# frozen_string_literal: true

module Appydave
  module Tools
    module Types
      # Used by the ActiveModel attributes API to cast values to arrays
      class ArrayType < ActiveModel::Type::Value
        def cast(value)
          case value
          when String
            value.split(',')
          when Array
            value
          else
            raise ArgumentError, "Cannot cast #{value.class} to Array"
          end
        end

        def serialize(value)
          value.join(',')
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
appydave-tools-0.9.5 lib/appydave/tools/types/array_type.rb
appydave-tools-0.9.4 lib/appydave/tools/types/array_type.rb