Class: DataMapper::Property::Record

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

Instance Method Summary collapse

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


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

def custom?
  true
end

#dump(value) ⇒ Object



32
33
34
# File 'lib/types/record.rb', line 32

def dump(value)
  value
end

#load(value) ⇒ Object



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

def load(value)
  if value.nil?
    nil
  elsif value.is_a?(::Array)
    klass = value.shift.capitalize
    theklass = Kernel.const_get(klass).new
    theklass.send('properties').map(&:name).each_with_index() do |k,i|
      theklass.send("#{k}=",value[i])
    end
    theklass
 else
    raise ArgumentError.new("not sure what type #{value.class}")
  end
end

#primitive?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#typecast_to_primitive(value) ⇒ Object



36
37
38
# File 'lib/types/record.rb', line 36

def typecast_to_primitive(value)
  value.to_s
end

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

Returns:

  • (Boolean)


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

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