Sha256: 178ab0d0ec29c635ecca98a4c4c096fb8acb1f48a86178f0f4eaa9ff216c35c5

Contents?: true

Size: 1.61 KB

Versions: 11

Compression:

Stored size: 1.61 KB

Contents

# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

return unless RUBY_VERSION < '2.6.0' # TODO: RUBY-714 remove guard w/ EOL of 2.5

module Contrast
  module Framework
    module Rails
      module Rewrite
        # Rails / ActiveRecord are sneaky. They define attributes of a class in
        # one method, then monkey patch allocate in another and finally invoke
        # module_eval in this method... but of course they use a '_tmp_' header
        # for the method name and then alias it in this module to name it what
        # we expect
        #
        # TODO: RUBY-714 remove w/ EOL of 2.5
        # @deprecated Changes to this class are discouraged as this approach is
        #   being phased out with support for those language versions.
        module ActiveRecordAttributeMethodsRead
          def self.instrument
            @_instrument ||= begin
              ::ActiveRecord::AttributeMethods::Read::ClassMethods.class_eval do
                alias_method :cs__patched_define_method_attribute, :define_method_attribute

                def define_method_attribute *args, &block
                  ret = cs__patched_define_method_attribute(*args, &block)
                  method_name = args[0]
                  Contrast::Agent::Assess::Policy::Patcher.patch_assess_method(self, method_name)
                  ret
                end

                protected :cs__patched_define_method_attribute, :define_method_attribute
              end
              true
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
contrast-agent-4.14.1 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.14.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.13.1 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.13.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.12.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.11.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.10.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.9.1 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.9.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.8.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.7.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb