lib/rake/funnel/support/patch.rb in rake-funnel-0.3.2.pre vs lib/rake/funnel/support/patch.rb in rake-funnel-0.4.0.pre

- old
+ new

@@ -1,37 +1,41 @@ -module Rake::Funnel::Support - class Patch - def initialize(context = nil) - @context = context - - yield self if block_given? - end - - def setup(&block) - @setup = block - end - - def reset(&block) - @reset = block - end - - def apply! - return self if @memo - @memo = (@setup || noop).call(@context) - - self - end - - def revert! - return self unless @memo - (@reset || noop).call(@memo) - @memo = nil - - self - end - - private - def noop - Proc.new { } - end - end -end +module Rake + module Funnel + module Support + class Patch + def initialize(context = nil) + @context = context + + yield self if block_given? + end + + def setup(&block) + @setup = block + end + + def reset(&block) + @reset = block + end + + def apply! + return self if @memo + @memo = (@setup || noop).call(@context) + + self + end + + def revert! + return self unless @memo + (@reset || noop).call(@memo) + @memo = nil + + self + end + + private + def noop + proc {} + end + end + end + end +end