Commit cdabd05

mo khan <mo@mokhan.ca>
2013-05-22 04:17:54
extract Results object to centralize query optimization and proxy generation
1 parent 84b3ae3
Changed files (1)
spec
integration
spec/integration/fixtures/movie_mapping.rb
@@ -16,9 +16,7 @@ class MovieMapping
   end
 
   def find_all_using(connection, clazz)
-    connection[:movies].map do |row|
-      Movie.new(row)
-    end
+    Results.new(connection[:movies], MovieMapper.new)
   end
 
   def run(map)
@@ -26,3 +24,24 @@ class MovieMapping
   end
 end
 
+class MovieMapper
+  def map_from(row)
+    Movie.new(row)
+  end
+end
+
+class Results
+  include Enumerable
+
+  def initialize(rows, mapper)
+    @rows = rows
+    @mapper = mapper
+  end
+
+  def each(&block)
+    @rows.each do |row|
+      block.call(@mapper.map_from(row))
+    end
+  end
+end
+