Sha256: c8b27a4982cd661cd3725beb98f6265b73d84b5ce6ecaaf631ae850bcc21785e

Contents?: true

Size: 1.53 KB

Versions: 4

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.
        class 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

4 entries across 4 versions & 1 rubygems

Version Path
contrast-agent-4.2.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.1.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-4.0.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-3.16.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb