- fix case where literal names wouldn't invoke a block.

thing.call("foo") { ... } would not invoke the block
   but thing.call("[foo]") would.

   Both work now and have test cases.
This commit is contained in:
Jordan Sissel 2013-08-08 23:26:05 -07:00
parent c6e379e931
commit 1d45784c68

View file

@ -3,8 +3,13 @@ require "logstash/util"
module LogStash::Util::HashEval
def compile(str)
if str[0] != '['
return "lambda { |e, &block| return e[#{str.inspect}] }"
if str[0,1] != '['
return <<-"CODE"
lambda do |e, &block|
block.call(e, #{str.inspect}) unless block.nil?
return e[#{str.inspect}]
end
CODE
end
code = "lambda do |e, &block|\n"
@ -29,6 +34,7 @@ module LogStash::Util::HashEval
end
code << "return e\nend"
#puts code
return code
end # def compile