Permalink
Browse files

handle Hash + Array correctly

  • Loading branch information...
1 parent cadb192 commit 90c24f8d0f2058f4cf6af819ac58ed1808cc3fb7 @mkristian committed Nov 21, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/ixtlan/babel/hash_filter.rb
@@ -90,7 +90,9 @@ def filter_data(model, data, options = {}, &block)
unless data.include?(m)
raise "no block given to calculate the attributes from model" unless block
models_or_model = model.send(m)
- if models_or_model.respond_to?(:collect)
+ if models_or_model.is_a?(Array) && models_or_model.first.is_a?(String)
+ data[m] = models_or_model
+ elsif models_or_model.respond_to?(:collect)
data[m] = models_or_model.collect { |i| block.call(i) }
else
data[m]= block.call(model.send(m))
@@ -127,8 +129,12 @@ def filter_data(model, data, options = {}, &block)
end
end
when Hash
- opts = include[k]
- result[k.to_s] = v.collect { |i| j += 1; filter_data(models[j], i, opts, &block) }
+ opts = include[k.to_s]
+ result[k.to_s] = v.collect do |i|
+ j += 1
+ ndata = i.is_a?(Hash)? i : block.call(i)
+ filter_data(models[j], ndata, opts, &block)
+ end
end
end
else

0 comments on commit 90c24f8

Please sign in to comment.