Sha256: c0fca2149e9ebedb8d77d56f4c1a7ea4dfe122ba80ed2e6ccfebeb04a3984c35

Contents?: true

Size: 1.68 KB

Versions: 8

Compression:

Stored size: 1.68 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

8 entries across 8 versions & 1 rubygems

Version Path
contrast-agent-3.15.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-3.14.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-3.13.2 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-3.13.1 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-3.13.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-3.12.2 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-3.12.1 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb
contrast-agent-3.12.0 lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb