Sha256: 5611f386eb18626e1c8c0a6fa7fdc02558570b37bd727f5bec5e84cfef61af21

Contents?: true

Size: 615 Bytes

Versions: 3

Compression:

Stored size: 615 Bytes

Contents

module Acfs::Resource::Attributes

  # @api public
  #
  # List attribute type. Use it in your model as an attribute type:
  #
  # @example
  #   class User < Acfs::Resource
  #     attribute :name, :list
  #   end
  #
  class List < Base

    # @api public
    #
    # Cast given object to a list.
    #
    # @param [Object] obj Object to cast.
    # @return [Fixnum] Casted object as list.
    # @raise [TypeError] If object cannot be casted to a list.
    #
    def cast_type(obj)
      return obj.to_a if obj.respond_to? :to_a
      raise TypeError.new "Cannot cast #{obj.inspect} to array."
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acfs-1.0.0.dev.1.b305 lib/acfs/resource/attributes/list.rb
acfs-1.0.0.dev.1.b298 lib/acfs/resource/attributes/list.rb
acfs-1.0.0.dev.1.b297 lib/acfs/resource/attributes/list.rb