mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
- Rename HashEval -> FieldReference (LOGSTASH-1250)
This commit is contained in:
parent
91ccbd855b
commit
cd102cd39d
3 changed files with 9 additions and 16 deletions
|
@ -2,7 +2,7 @@ require "json"
|
|||
require "time"
|
||||
require "date"
|
||||
require "logstash/namespace"
|
||||
require "logstash/util/fieldeval"
|
||||
require "logstash/util/fieldreference"
|
||||
|
||||
# Use a custom serialization for jsonifying Time objects.
|
||||
# TODO(sissel): Put this in a separate file.
|
||||
|
@ -114,20 +114,20 @@ class LogStash::Event
|
|||
def [](str)
|
||||
if str[0,1] == "+"
|
||||
else
|
||||
return LogStash::Util::HashEval.exec(str, @data)
|
||||
return LogStash::Util::FieldReference.exec(str, @data)
|
||||
end
|
||||
end # def []
|
||||
|
||||
public
|
||||
def []=(str, value)
|
||||
r = LogStash::Util::HashEval.exec(str, @data) do |obj, key|
|
||||
r = LogStash::Util::FieldReference.exec(str, @data) do |obj, key|
|
||||
obj[key] = value
|
||||
end
|
||||
|
||||
# The assignment can fail if the given field reference (str) does not exist
|
||||
# In this case, we'll want to set the value manually.
|
||||
if r.nil?
|
||||
# TODO(sissel): Implement this in LogStash::Util::HashEval
|
||||
# TODO(sissel): Implement this in LogStash::Util::FieldReference
|
||||
if str[0,1] != "["
|
||||
return @data[str] = value
|
||||
end
|
||||
|
@ -181,7 +181,7 @@ class LogStash::Event
|
|||
# Remove a field. Returns the value of that field when deleted
|
||||
public
|
||||
def remove(field)
|
||||
return LogStash::Util::HashEval.exec(str, @data) do |obj, key|
|
||||
return LogStash::Util::FieldReference.exec(str, @data) do |obj, key|
|
||||
obj.delete(key)
|
||||
end
|
||||
end # def remove
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require "logstash/namespace"
|
||||
require "logstash/util"
|
||||
|
||||
module LogStash::Util::HashEval
|
||||
module LogStash::Util::FieldReference
|
||||
def compile(str)
|
||||
if str[0,1] != '['
|
||||
return <<-"CODE"
|
||||
|
@ -45,4 +45,4 @@ module LogStash::Util::HashEval
|
|||
end
|
||||
|
||||
extend self
|
||||
end # module LogStash::Util::HashEval
|
||||
end # module LogStash::Util::FieldReference
|
|
@ -1,13 +1,6 @@
|
|||
require "logstash/util/fieldeval"
|
||||
require "logstash/util/fieldreference"
|
||||
|
||||
describe LogStash::Util::HashEval do
|
||||
it "xxx" do
|
||||
str = "[hello][world]"
|
||||
#puts subject.compile(str)
|
||||
end
|
||||
end
|
||||
|
||||
describe LogStash::Util::HashEval, :if => true do
|
||||
describe LogStash::Util::FieldReference, :if => true do
|
||||
it "should permit simple key names" do
|
||||
str = "hello"
|
||||
m = eval(subject.compile(str))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue