Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Commit

Permalink
Cover ParamsRenderer, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulik committed Feb 10, 2023
1 parent 62aef82 commit 38d1fec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/nats_streamer/listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run

private

memoize def params_renderer = NatsStreamer::ParamsRenderer.new(subject:, subscriber:)
memoize def params_renderer = NatsStreamer::ParamsRenderer.new(subject:, params: subscriber.params)
memoize def deliverer(subscriber) = NatsStreamer::Deliverer.new(subscriber:)

def pull(&)
Expand Down
4 changes: 2 additions & 2 deletions lib/nats_streamer/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module NatsStreamer::Logger
Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
end

return Console.logger.public_send(name, self, msg) { block.call(elapsed) } unless block.nil?
return public_send(name, msg) { block.call(elapsed) } unless block.nil?

Console.logger.public_send(name, self, msg)
public_send(name, msg)
end
end
end
4 changes: 2 additions & 2 deletions lib/nats_streamer/params_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class NatsStreamer::ParamsRenderer
include Memery

option :subject
option :subscriber
option :params

def render(event)
subscriber.params.transform_values do |v|
params.transform_values do |v|
binding.local_variable_set(:event, event)
ERB.new(v).result(binding)
end.merge(event:, subject:)
Expand Down
20 changes: 20 additions & 0 deletions spec/nats_streamer/params_renderer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

RSpec.describe NatsStreamer::ParamsRenderer do
let(:renderer) { described_class.new(subject: subject_name, params:) }

let(:subject_name) { "foo.bar" }
let(:params) { { template: "The template, payload=<%= event[:payload] %>" } }

describe "#render" do
subject { renderer.render({ payload: "test" }) }

it "returns rendered parameters" do
expect(subject).to eq({
template: "The template, payload=test",
event: { payload: "test" },
subject: "foo.bar"
})
end
end
end

0 comments on commit 38d1fec

Please sign in to comment.