Class: DataMapper::Property::List

Inherits:
Text
  • Object
show all
Defined in:
lib/types/list.rb

Instance Method Summary collapse

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/types/list.rb', line 4

def custom?
  true
end

#dump(value) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/types/list.rb', line 29

def dump(value)
  if value.is_a?(::String)
    value
  else
    "[#{value.join(",").to_s}]"
  end
end

#load(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/types/list.rb', line 16

def load(value)
  if value.nil?
    Array.new
  elsif value.is_a?(::Array)
    value
  elsif value.is_a?(::String)
    value
 else
    raise ArgumentError.new("not sure what type #{value.class}")
  end
end

#primitive?(value) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/types/list.rb', line 8

def primitive?(value)
  value.kind_of?(::Array) || value.kind_of?(::String)
end

#typecast_to_primitive(value) ⇒ Object



37
38
39
# File 'lib/types/list.rb', line 37

def typecast_to_primitive(value)
  value.to_s
end

#valid?(value, negated = false) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/types/list.rb', line 12

def valid?(value, negated = false)
  super || dump(value).kind_of?(::String)
end