lib/contrast.rb in contrast-agent-6.3.0 vs lib/contrast.rb in contrast-agent-6.4.0
- old
+ new
@@ -19,10 +19,43 @@
alias_method :cs__method, :method
alias_method :cs__respond_to?, :respond_to?
alias_method :cs__singleton_class, :singleton_class
end
+# ActiveRecord gives access to the `String#blank?` method, which we've started using. We need to make sure that method
+# actually exists.
+# From https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/object/blank.rb
+class String
+ unless cs__respond_to?(:blank?)
+
+ CS__BLANK_RE = /\A[[:space:]]*\z/.cs__freeze
+ # A string is blank if it's empty or contains whitespaces only:
+ #
+ # ''.blank? # => true
+ # ' '.blank? # => true
+ # "\t\n\r".blank? # => true
+ # ' blah '.blank? # => false
+ #
+ # Unicode whitespace is supported:
+ #
+ # "\u00a0".blank? # => true
+ #
+ # @return [true, false]
+ def blank?
+ # The regexp that matches blank strings is expensive. For the case of empty
+ # strings we can speed up this method (~3.5x) with an empty? call. The
+ # penalty for the rest of strings is marginal.
+ empty? ||
+ begin
+ CS__BLANK_RE.match?(self)
+ rescue Encoding::CompatibilityError
+ false
+ end
+ end
+ end
+end
+
if RUBY_VERSION >= '3.0.0' && RUBY_VERSION < '3.1.0'
# This fixes Ruby 3.0 issues with Module#(some instance method) patching by preventing the prepending of
# a JSON helper on protobuf load. String.instance_method(:+) is one of the most noticeable.
# This is fixed in Ruby 3.1.0
# TODO: RUBY-1132 Remove this once Ruby 3 support is dropped.
@@ -48,9 +81,10 @@
require 'contrast/components/scope'
require 'contrast/components/settings'
require 'contrast/utils/telemetry_hash'
require 'contrast/utils/telemetry'
require 'contrast/agent/telemetry/events/exceptions/telemetry_exception_event'
+require 'protobuf' # TODO: RUBY-1438
module Contrast
API = Contrast::Components::Api::Interface.new
SCOPE = Contrast::Components::Scope::Interface.new
CONFIG = Contrast::Components::Config::Interface.new