Permalink
Browse files

cleaned up code

  • Loading branch information...
mkristian committed Dec 12, 2013
1 parent 4c3bbe9 commit 9f58649cfd811e619844b958829b424b0f33138d
Showing with 13 additions and 10 deletions.
  1. +13 −10 lib/ixtlan/babel/params_filter.rb
@@ -130,19 +130,22 @@ def filter_it( data )
data = data.dup
data = data[ filter.options[ :root ] ] if filter.options[ :root ]
keeps = {}
- ( filter.options[ :keep ] || [] ).each do |k|
- keep = data[ k.to_s ] || data[ k.to_sym ]
- keeps[ k.to_s ] = data.delete( k.to_s ) ||
- data.delete( k.to_sym ) unless keep.is_a? Hash
+ opts = ( filter.options[ :keep ] || [] ).collect { |k| k.to_s }
+ opts.each do |k|
+ keep = data[ k ] || data[ k.to_sym ]
+ unless keep.is_a? Hash
+ keeps[ k ] = data.delete( k ) || data.delete( k.to_sym )
+ end
end
- filtered_data = filter.filter( data )
- ( filter.options[ :keep ] || [] ).each do |k|
- keeps[ k.to_s ] = filtered_data.delete( k.to_s ) ||
- filtered_data.delete( k.to_sym ) unless keeps.member?( k.to_s )
+ filtered = filter.filter( data )
+ opts.each do |k|
+ unless keeps.member?( k )
+ keeps[ k ] = filtered.delete( k ) || filtered.delete( k.to_sym )
+ end
# just make sure we have an entry for each keeps key
- keeps[ k.to_s ] ||= nil
+ keeps[ k ] ||= nil
end
- FilterResult.new( @model_class, filtered_data, keeps )
+ FilterResult.new( @model_class, filtered, keeps )
end
end
end

0 comments on commit 9f58649

Please sign in to comment.