Sha256: 504a13f31840111b48274b97f0b86576a535ae3f8a3d3098194b013c5abc1945

Contents?: true

Size: 742 Bytes

Versions: 1

Compression:

Stored size: 742 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] value Object to cast.
    # @return [Fixnum] Casted object as list.
    # @raise [TypeError] If object cannot be casted to a list.
    #
    def cast_value(value)
      return nil if value.blank?

      if value.is_a?(::Array)
        value
      elsif value.respond_to?(:to_ary)
        value.to_ary
      elsif value.respond_to?(:to_a)
        value.to_a
      else
        Array(value)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acfs-0.46.0 lib/acfs/resource/attributes/list.rb