Only store one proc per BuildEnvironment instance

This commit is contained in:
Jack Nagel 2014-07-07 17:34:30 -05:00
parent 9e7f5dc261
commit 879ec96743
2 changed files with 8 additions and 10 deletions

View File

@ -1,9 +1,10 @@
require 'set'
class BuildEnvironment
attr_accessor :proc
def initialize(*settings)
@settings = Set.new(settings)
@procs = Set.new
end
def merge(*args)
@ -11,10 +12,7 @@ class BuildEnvironment
end
def <<(o)
case o
when Proc then @procs << o
else @settings << o
end
@settings << o
self
end
@ -27,7 +25,7 @@ class BuildEnvironment
end
def modify_build_environment(receiver)
@procs.each { |p| receiver.instance_eval(&p) }
receiver.instance_eval(&proc)
end
def _dump(*)
@ -43,7 +41,7 @@ module BuildEnvironmentDSL
def env(*settings, &block)
@env ||= BuildEnvironment.new
if block_given?
@env << block
@env.proc = block
else
@env.merge(settings)
end

View File

@ -21,7 +21,7 @@ class BuildEnvironmentTests < Homebrew::TestCase
end
def test_modify_build_environment
@env << Proc.new { raise StandardError }
@env.proc = Proc.new { raise StandardError }
assert_raises(StandardError) do
@env.modify_build_environment(self)
end
@ -36,14 +36,14 @@ class BuildEnvironmentTests < Homebrew::TestCase
def test_env_block
foo = mock("foo")
@env << Proc.new { foo.some_message }
@env.proc = Proc.new { foo.some_message }
foo.expects(:some_message)
@env.modify_build_environment(self)
end
def test_env_block_with_argument
foo = mock("foo")
@env << Proc.new { |x| x.some_message }
@env.proc = Proc.new { |x| x.some_message }
foo.expects(:some_message)
@env.modify_build_environment(foo)
end