lib/rbbt/tsv/accessor.rb in rbbt-util-5.5.58 vs lib/rbbt/tsv/accessor.rb in rbbt-util-5.5.59
- old
+ new
@@ -1,6 +1,7 @@
require 'yaml'
+require 'rbbt/annotations'
module TSV
TSV_SERIALIZER = YAML
SERIALIZED_NIL = TSV_SERIALIZER.dump nil
@@ -246,10 +247,11 @@
#{{{ Sorting
def sort_by(field = nil, just_keys = false, &block)
field = :all if field.nil?
+
if field == :all
elems = collect
else
elems = []
case type
@@ -296,20 +298,21 @@
else
a_value <=> b_value
end
end
if just_keys
- #keys = elems.sort_by{|key, value| value }.collect{|key, value| key}
keys = sorted.collect{|key, value| key}
- keys = prepare_entity(keys, key_field, entity_options.merge(:dup_array => true))
+ keys = prepare_entity(keys, key_field, entity_options.merge(:dup_array => true)) unless @unnamed
keys
else
sorted.collect{|key, value| [key, self[key]]}
end
end
else
if just_keys
- elems.sort_by(&block).collect{|key, value| key}
+ keys = elems.sort_by(&block).collect{|key, value| key}
+ keys = prepare_entity(keys, key_field, entity_options.merge(:dup_array => true)) unless @unnamed
+ keys
else
elems.sort_by(&block).collect{|key, value| [key, self[key]]}
end
end
end