Class: Datadog::Tracing::Contrib::Propagation::SqlComment::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb

Overview

To be prepended to a sql statement.

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Comment

Returns a new instance of Comment.



12
13
14
# File 'lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb', line 12

def initialize(hash)
  @hash = hash
end

Instance Method Details

#to_sObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb', line 16

def to_s
  @string ||= begin
    ret = String.new

    @hash.each do |key, value|
      next if value.nil?

      # Url encode
      value = ERB::Util.url_encode(value)

      # Escape SQL
      ret << "#{key}='#{value}',"
    end

    # Remove the last `,`
    ret.chop!

    "/*#{ret}*/"
  end
end