Class: Acfs::Resource::Attributes::List

Inherits:
Base
  • Object
show all
Defined in:
lib/acfs/resource/attributes/list.rb

Overview

List attribute type. Use it in your model as an attribute type:

Examples:

class User < Acfs::Resource
  attribute :name, :list
end

Instance Attribute Summary

Attributes inherited from Base

#default

Instance Method Summary collapse

Methods inherited from Base

#cast, #default_value, #initialize

Constructor Details

This class inherits a constructor from Acfs::Resource::Attributes::Base

Instance Method Details

#cast_value(value) ⇒ Fixnum

Cast given object to a list.

Parameters:

  • value (Object)

    Object to cast.

Returns:

  • (Fixnum)

    Casted object as list.

Raises:

  • (TypeError)

    If object cannot be casted to a list.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/acfs/resource/attributes/list.rb', line 22

def cast_value(value)
  return [] 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