class MetaEvents::TestReceiver
A MetaEvents::TestReceiver
is a very simple object that conforms to the call signature required by the MetaEvents::Tracker
for event receivers. It writes each event as human-readable text to a target
, which can be:
-
A block (or any object that responds to call), which will be passed a String;
-
A Logger (or any object that responds to info), which will be passed a String;
-
An IO (like
STDOUT
orSTDERR
, or any object that responds to puts), which will be passed a String.
This object is useful for watching and debugging events in development environments.
Public Class Methods
new(target = nil, &block)
click to toggle source
# File lib/meta_events/test_receiver.rb, line 11 def initialize(target = nil, &block) @target = target || block || lambda { |string| ::Rails.logger.info(string) } end
Public Instance Methods
say(string)
click to toggle source
# File lib/meta_events/test_receiver.rb, line 27 def say(string) if @target.respond_to?(:call) @target.call "#{string}\n" elsif @target.respond_to?(:info) @target.info "#{string}" else @target.puts string end end
track(distinct_id, event_name, properties)
click to toggle source
# File lib/meta_events/test_receiver.rb, line 15 def track(distinct_id, event_name, properties) string = "Tracked event: #{event_name.inspect} for user #{distinct_id.inspect}" properties.keys.sort.each do |k| value = properties[k] unless value == nil string << "\n %30s: %s" % [ k, properties[k] ] end end say(string) end