Skip to content

Commit

Permalink
feat(point): specify tags as a NamedTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
kimburgess committed Dec 16, 2019
1 parent 1fc30e3 commit 3233cae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion spec/influx_db/line_protocol_spec.cr
Expand Up @@ -17,7 +17,7 @@ describe InfluxDB::LineProtocol do

it "serializes when tags are present" do
point = InfluxDB::Point.new "foo", time, a: 1
point.tag :test, "bar"
point.tag test: "bar"
InfluxDB::LineProtocol.serialize(point).should eq("foo,test=bar a=1 #{ts}")
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/influx_db/point_spec.cr
Expand Up @@ -29,7 +29,7 @@ describe InfluxDB::Point do
describe "#tag" do
it "allows tagging of points" do
point = InfluxDB::Point["foo", a: 1]
point.tag :test, "bar"
point.tag test: "bar"
point.tags.should eq({:test => "bar"})
end
end
Expand All @@ -39,7 +39,7 @@ describe InfluxDB::Point do
time = Time.utc
ts = time.to_unix
point = InfluxDB::Point.new "foo", time, a: 1
point.tag :test, "bar"
point.tag test: "bar"
point.to_s.should eq("foo,test=bar a=1 #{ts}")
end
end
Expand Down
8 changes: 5 additions & 3 deletions src/influx_db/point.cr
Expand Up @@ -28,9 +28,11 @@ struct InfluxDB::Point
{% end %}
end

# Append or change a tag on the point.
def tag(key, value)
tags[key] = value
# Append or change tags associated with the point.
def tag(**t : **T) forall T
{% for k in T %}
tags[{{k.symbolize}}] = t[{{k.symbolize}}]
{% end %}
end

# Checks if any tags are defined for the point.
Expand Down

0 comments on commit 3233cae

Please sign in to comment.