lib/rbbt/tsv/accessor.rb in rbbt-util-5.7.0 vs lib/rbbt/tsv/accessor.rb in rbbt-util-5.8.0
- old
+ new
@@ -5,12 +5,16 @@
TSV_SERIALIZER = YAML
SERIALIZED_NIL = TSV_SERIALIZER.dump nil
attr_accessor :unnamed, :serializer_module, :entity_options, :entity_templates
+ def info
+ {:key_field => key_field, :fields => fields, :namespace => namespace, :entity_options => entity_options, :type => type, :filename => filename, :identifiers => identifiers, :unnamed => unnamed}.delete_if{|k,v| v.nil? }
+ end
+
def annotate(tsv)
- TSV.setup(tsv, :key_field => key_field, :fields => fields, :namespace => namespace, :entity_options => entity_options, :type => type, :filename => filename, :identifiers => identifiers, :unnamed => unnamed)
+ TSV.setup(tsv, info)
end
def entity_options
if @entity_options.nil?
@entity_options = namespace ? {:namespace => namespace, :organism => namespace} : {}
@@ -147,18 +151,20 @@
attr_reader :serializer_module
def serializer=(serializer)
@serializer = serializer
self.send(:[]=, KEY_PREFIX + 'serializer', (serializer.nil? ? SERIALIZED_NIL : TSV_SERIALIZER.dump(serializer)), :entry_key)
- @serializar_module = serializer.nil? ? nil : SERIALIZER_ALIAS[serializer.to_sym]
+ @serializar_module = serializer.nil? ? TSV::CleanSerializer : SERIALIZER_ALIAS[serializer.to_sym]
end
def serializer_module
- @serializar_module ||= begin
+ @serializer_module ||= begin
serializer = self.serializer
- serializer.nil? ? TSV::CleanSerializer : SERIALIZER_ALIAS[serializer.to_sym]
+ mod = serializer.nil? ? TSV::CleanSerializer : SERIALIZER_ALIAS[serializer.to_sym]
+ raise "No serializer_module for: #{ serializer.inspect }" if mod.nil?
+ mod
end
end
def empty?
length == 0
@@ -168,12 +174,14 @@
def [](key, clean = false)
value = super(key)
return value if clean or value.nil?
+ @serializer_module ||= self.serializer_module
- value = serializer_module.load(value) if serializer_module and not TSV::CleanSerializer === serializer_module
+ value = @serializer_module.load(value) if @serializer_module and not TSV::CleanSerializer == @serializer_module
+
return value if @unnamed or fields.nil?
case type
when :double, :list
setup_array value, fields, key, entity_options, entity_templates
@@ -184,15 +192,12 @@
end
value
end
def []=(key, value, clean = false)
- if clean or serializer_module.nil? or TSV::CleanSerializer === serializer_module or value.nil?
- return super(key, value)
- else
- return super(key, serializer_module.dump(value))
- end
+ return super(key, value) if clean or value.nil? or TSV::CleanSerializer == self.serializer_module
+ super(key, @serializer_module.dump(value))
end
def zip_new(key, values)
if self.include? key
new = []
@@ -229,24 +234,23 @@
end
def each
fields = self.fields
- serializer = self.serializer
serializer_module = self.serializer_module
super do |key, value|
next if ENTRY_KEYS.include? key
# TODO Update this to be more efficient
- value = serializer_module.load(value) unless serializer_module.nil? or TSV::CleanSerializer === serializer_module
+ value = serializer_module.load(value) unless serializer_module.nil? or TSV::CleanSerializer == serializer_module
# Annotated with Entity and NamedArray
if not @unnamed
if not fields.nil?
case type
when :double, :list
- setup_array value, fields, key, entity_options, entity_templates if Array === value
+ setup_array value, fields, key, entity_options, entity_templates if Array == value
when :flat, :single
prepare_entity(value, fields.first, entity_options)
end
end
key = prepare_entity(key, key_field, entity_options)
@@ -256,16 +260,15 @@
[key, value]
end
end
def collect
- serializer = self.serializer
serializer_module = self.serializer_module
super do |key, value|
next if ENTRY_KEYS.include? key
# TODO Update this to be more efficient
- value = serializer_module.load(value) unless serializer_module.nil? or TSV::CleanSerializer === serializer_module
+ value = serializer_module.load(value) unless serializer_module.nil? or TSV::CleanSerializer == serializer_module
# Annotated with Entity and NamedArray
if not @unnamed
if not fields.nil?
case type