summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/humble/column.rb34
1 files changed, 31 insertions, 3 deletions
diff --git a/lib/humble/column.rb b/lib/humble/column.rb
index 7582a00..2a3b238 100644
--- a/lib/humble/column.rb
+++ b/lib/humble/column.rb
@@ -75,13 +75,41 @@ module Humble
end
def apply(row, entity, session)
- puts "#{@attribute} #{@type} #{row} #{entity}"
- items = session.find_all(@type)
- entity.public_send("#{@attribute}=", items)
+ proxy = ArrayProxy.new(session, @type, @attribute, entity)
+ entity.public_send("#{@attribute}=", proxy)
end
def prepare(entity)
{ }
end
end
+
+ class ArrayProxy
+ include Enumerable
+
+ def initialize(session, type, attribute, parent_entity)
+ @session = session
+ @type = type
+ @attribute = attribute
+ @parent = parent_entity
+ end
+
+ def each
+ items.each do |item|
+ yield item
+ end
+ end
+
+ def inspect
+ "[#{map { |x| x.inspect }.join(", ")}]"
+ end
+
+ private
+
+ def items
+ @items ||= @session.find_all(@type).find_all do |item|
+ item.movie && item.movie.id == @parent.id
+ end
+ end
+ end
end