Permalink
Browse files

handle root differently with filter and deserializer

  • Loading branch information...
1 parent 2a5a184 commit 6cfd16be5a07ee378e380beea47789b729cb5e49 @mkristian committed Dec 7, 2012
Showing with 12 additions and 11 deletions.
  1. +8 −11 lib/ixtlan/babel/deserializer.rb
  2. +4 −0 lib/ixtlan/babel/hash_filter.rb
@@ -34,20 +34,17 @@ def use(context_or_options)
end
def from_hash(data, options = nil)
- filter.use(options) if options
- if root = filter.options[:root]
- if data.is_a? Array
- root = root.to_s
- data.collect{ |d| @model_class.new(filter.filter(d[root])) }
+ 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
- @model_class.new(filter.filter(data[root.to_s]))
+ data.collect{ |d| @model_class.new( filter.filter( d ) ) }
end
else
- if data.is_a? Array
- data.collect{ |d| @model_class.new(filter.filter(d)) }
- else
- @model_class.new(filter.filter(data))
- end
+ data = data[ filter.root.to_s ] if filter.root
+ @model_class.new( filter.filter( data ) )
end
end
@@ -66,6 +66,10 @@ def collection_options
@options || context[default_context_key[1]] || {}
end
+ def root
+ @root ||= single_options[:root]
+ end
+
private
def filter_data(model, data, options = {}, &block)

0 comments on commit 6cfd16b

Please sign in to comment.