Class: DataMapper::Property::Array

Inherits:
Text
  • Object
show all
Defined in:
lib/tentd/datamapper/array_property.rb

Overview

Implements flat postgres string arrays

Instance Method Summary collapse

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/tentd/datamapper/array_property.rb', line 5

def custom?
  true
end

#dump(value) ⇒ Object



14
15
16
# File 'lib/tentd/datamapper/array_property.rb', line 14

def dump(value)
  "{#{value.map(&:to_s).map(&:inspect).join(',')}}" unless value.nil?
end

#load(value) ⇒ Object



9
10
11
12
# File 'lib/tentd/datamapper/array_property.rb', line 9

def load(value)
  return value if value.kind_of? ::Array
  value[1..-2].split(',').map { |v| v[0,1] == '"' ? v[1..-2] : v  } unless value.nil?
end

#typecast(value) ⇒ Object



18
19
20
# File 'lib/tentd/datamapper/array_property.rb', line 18

def typecast(value)
  load(value)
end