lib/rbbt/tsv/accessor.rb in rbbt-util-5.13.36 vs lib/rbbt/tsv/accessor.rb in rbbt-util-5.13.37
- old
+ new
@@ -92,10 +92,11 @@
def read(force = false)
begin
super
rescue Exception
+ Log.exception $!
@writable = false
self
end
end
@@ -195,16 +196,11 @@
length == 0
end
#{{{ GETTERS AND SETTERS
-
- def [](key, clean = false)
- value = super(key)
- return value if clean or value.nil?
- @serializer_module ||= self.serializer_module
-
+ def prepare_value(key, value)
value = @serializer_module.load(value) if @serializer_module and not TSV::CleanSerializer == @serializer_module
return value if @unnamed or fields.nil?
case type
@@ -216,10 +212,24 @@
value = prepare_entity(value, fields.first, entity_options)
end
value
end
+ def [](key, clean = false)
+ value = super(key)
+ return value if clean or value.nil?
+ @serializer_module ||= self.serializer_module
+
+ if MultipleResult === value
+ res = value.collect{|v| prepare_value key, v }
+ res.extend MultipleResult
+ res
+ else
+ prepare_value key, value
+ end
+ end
+
def []=(key, value, clean = false)
return super(key, value) if clean or value.nil? or TSV::CleanSerializer == self.serializer_module
super(key, @serializer_module.dump(value))
end
@@ -632,10 +642,11 @@
field_pos = self.identify_field field
new.with_unnamed do
if merge
self.through do |key,values|
field_values = values.delete_at field_pos
+ next if field_values.nil?
zipped = values.zip_fields
field_values.zip(zipped).each do |field_value,rest|
k = [key,field_value]*":"
if new.include? k
new[k] = Misc.zip_fields(Misc.zip_fields(new[k]) << rest)
@@ -646,9 +657,10 @@
end
new.type = :double
else
self.through do |key,values|
field_values = values.delete_at field_pos
+ next if field_values.nil?
zipped = Misc.zip_fields(values)
field_values.zip(zipped).each do |field_value,rest|
k = [key,field_value]*":"
new[k] = rest
end