Permalink
Browse files

removed complexity

  • Loading branch information...
1 parent 6f05c0d commit 372a69e892ca6fb175040f855ebf7758fa1bf3bc @mkristian committed Dec 7, 2012
Showing with 12 additions and 8 deletions.
  1. +11 −7 lib/ixtlan/babel/deserializer.rb
  2. +1 −1 lib/ixtlan/babel/hash_filter.rb
@@ -32,18 +32,22 @@ def use(context_or_options)
filter.use(context_or_options)
self
end
+
+ def from_array_hash( data )
+ if filter.root
+ data.collect{ |d| @model_class.new( filter.filter( d[ filter.root ] ) ) }
+ else
+ data.collect{ |d| @model_class.new( filter.filter( d ) ) }
+ end
+ end
+ private :from_array_hash
def from_hash(data, options = nil)
filter.use( options ) if options
if data.is_a? Array
- if filter.root
- root = filter.root.to_s
- data.collect{ |d| @model_class.new( filter.filter( d[ root ] ) ) }
- else
- data.collect{ |d| @model_class.new( filter.filter( d ) ) }
- end
+ from_array_hash( data )
else
- data = data[ filter.root.to_s ] if filter.root
+ data = data[ filter.root ] if filter.root
@model_class.new( filter.filter( data ) )
end
end
@@ -67,7 +67,7 @@ def collection_options
end
def root
- @root ||= single_options[:root]
+ @root ||= single_options.key?(:root) ? single_options[:root].to_s : nil
end
private

0 comments on commit 372a69e

Please sign in to comment.