Sha256: 489e00c02ee804c47002bef596964ecb95b9c36ed064f8666db9b823ca674ae5

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

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

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

5 entries across 5 versions & 1 rubygems

Version Path
contrast-agent-4.4.1 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.4.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.3.2 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.3.1 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.3.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb