From b2f98c13a3308e6db618d6f3f9f706cbc19f13fd Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 03:16:14 -0700 Subject: Simplify parts and tests --- actionpack/lib/action_view/body_parts/future.rb | 16 ---------------- actionpack/lib/action_view/body_parts/queued.rb | 13 +++++-------- actionpack/lib/action_view/body_parts/threaded.rb | 13 ++++++++++++- 3 files changed, 17 insertions(+), 25 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/body_parts/future.rb b/actionpack/lib/action_view/body_parts/future.rb index a5291c6e8c..f03c2b395b 100644 --- a/actionpack/lib/action_view/body_parts/future.rb +++ b/actionpack/lib/action_view/body_parts/future.rb @@ -1,26 +1,10 @@ module ActionView module BodyParts class Future - def initialize(&block) - @block = block - @parts = [] - end - def to_s finish body end - - protected - def work - @block.call(@parts) - end - - def body - str = '' - @parts.each { |part| str << part.to_s } - str - end end end end diff --git a/actionpack/lib/action_view/body_parts/queued.rb b/actionpack/lib/action_view/body_parts/queued.rb index f8501f6a85..618999742b 100644 --- a/actionpack/lib/action_view/body_parts/queued.rb +++ b/actionpack/lib/action_view/body_parts/queued.rb @@ -3,18 +3,15 @@ require 'action_view/body_parts/future' module ActionView module BodyParts class Queued < Future - def initialize(job, &block) - super(&block) - enqueue(job) + attr_reader :body + + def initialize(job) + @receipt = enqueue(job) end protected - def enqueue(job) - @receipt = submit(job) - end - def finish - @parts << redeem(@receipt) + @body = redeem(@receipt) end end end diff --git a/actionpack/lib/action_view/body_parts/threaded.rb b/actionpack/lib/action_view/body_parts/threaded.rb index 34800bf9c7..a2347a2f0e 100644 --- a/actionpack/lib/action_view/body_parts/threaded.rb +++ b/actionpack/lib/action_view/body_parts/threaded.rb @@ -4,11 +4,22 @@ module ActionView module BodyParts class Threaded < Future def initialize(concurrent = false, &block) - super(&block) + @block = block + @parts = [] concurrent ? start : work end protected + def work + @block.call(@parts) + end + + def body + str = '' + @parts.each { |part| str << part.to_s } + str + end + def start @worker = Thread.new { work } end -- cgit v1.2.3