Sha256: 8ba4e683b822f685fd1bf482dc84276c7d46dc87ae05c4a6a9afbd6e5271c0b3
Contents?: true
Size: 902 Bytes
Versions: 2
Compression:
Stored size: 902 Bytes
Contents
module TestTrack::Analytics class SafeWrapper attr_reader :underlying def initialize(underlying) @underlying = underlying end def error_handler=(handler) raise ArgumentError, "error_handler must be a lambda" unless handler.lambda? raise ArgumentError, "error_handler must accept 1 argument" unless handler.arity == 1 @error_handler = handler end def track_assignment(visitor_id, assignment) safe_action { underlying.track_assignment(visitor_id, assignment) } end def sign_up!(visitor_id) safe_action { underlying.sign_up!(visitor_id) } if underlying.respond_to?(:sign_up!) end private def error_handler @error_handler || ->(e) do Rails.logger.error e end end def safe_action yield true rescue StandardError => e error_handler.call e false end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
test_track_rails_client-3.0.1 | app/models/test_track/analytics/safe_wrapper.rb |
test_track_rails_client-3.0.0 | app/models/test_track/analytics/safe_wrapper.rb |