Sha256: 64d9202387dd8bae3703186eac314a762ab4d7a0bb60b0a3a67a05e6fcc235b4
Contents?: true
Size: 1.92 KB
Versions: 7
Compression:
Stored size: 1.92 KB
Contents
/* Copyright (c) 2020 Contrast Security, Inc. See * https://www.contrastsecurity.com/enduser-terms-0317a for more details. */ #include "cs__active_record_named.h" #include <ruby.h> VALUE contrast_assess_active_record_scope(const int argc, const VALUE *argv, const VALUE self) { /* * The ActiveRecord::Scoping::Named::ClassMethods#scope method allows for * the creation of methods at runtime. In order to trigger on interpolation * within that new method, we must rewrite the method body BEFORE it can be * used in the original #scope method, replacing interpolations with our * String append logic. As this deviates from standard Assess behavior * (changes the application behavior and acts on an input BEFORE it can be * passed to the original method), I think it deserves to be in a custom * call. -HM */ VALUE new_body, ret; VALUE new_args[3]; new_body = rb_funcall(self, rb_sym_assess_rewrite, 2, argv[0], argv[1]); new_args[0] = argv[0]; if (NIL_P(new_body)) { new_args[1] = argv[1]; } else { new_args[1] = new_body; } new_args[2] = argv[2]; ret = rb_funcall2(self, rb_sym_assess_scope, argc, new_args); return ret; } void Init_cs__assess_active_record_named(void) { rb_sym_assess_rewrite = rb_intern("_cs__rewrite"); rb_sym_assess_scope = rb_intern("cs__patched_scope"); VALUE active_record_module = rb_define_module("ActiveRecord"); VALUE scoping_module = rb_define_module_under(active_record_module, "Scoping"); VALUE named_module = rb_define_module_under(scoping_module, "Named"); VALUE class_methods_module = rb_define_module_under(named_module, "ClassMethods"); contrast_alias_method(class_methods_module, "cs__patched_scope", "scope"); rb_define_method(class_methods_module, "scope", contrast_assess_active_record_scope, -1); }
Version data entries
7 entries across 7 versions & 1 rubygems