@@ -7,20 +7,6 @@ private import codeql.ruby.ast.internal.Module
7
7
private import codeql.ruby.ApiGraphs
8
8
private import codeql.ruby.frameworks.StandardLibrary
9
9
10
- private class ActiveRecordBaseAccess extends ConstantReadAccess {
11
- ActiveRecordBaseAccess ( ) {
12
- this .getName ( ) = "Base" and
13
- this .getScopeExpr ( ) .( ConstantAccess ) .getName ( ) = "ActiveRecord"
14
- }
15
- }
16
-
17
- // ApplicationRecord extends ActiveRecord::Base, but we
18
- // treat it separately in case the ApplicationRecord definition
19
- // is not in the database
20
- private class ApplicationRecordAccess extends ConstantReadAccess {
21
- ApplicationRecordAccess ( ) { this .getName ( ) = "ApplicationRecord" }
22
- }
23
-
24
10
/// See https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html
25
11
private string activeRecordPersistenceInstanceMethodName ( ) {
26
12
result =
@@ -41,26 +27,28 @@ private predicate isBuiltInMethodForActiveRecordModelInstance(string methodName)
41
27
}
42
28
43
29
/**
44
- * A `ClassDeclaration` for a class that extends `ActiveRecord::Base`. For example,
30
+ * A `ClassDeclaration` for a class that inherits from `ActiveRecord::Base`. For example,
45
31
*
46
32
* ```rb
47
33
* class UserGroup < ActiveRecord::Base
48
34
* has_many :users
49
35
* end
36
+ *
37
+ * class SpecialUserGroup < UserGroup
38
+ * end
50
39
* ```
51
40
*/
52
41
class ActiveRecordModelClass extends ClassDeclaration {
53
42
ActiveRecordModelClass ( ) {
54
43
// class Foo < ActiveRecord::Base
55
- this .getSuperclassExpr ( ) instanceof ActiveRecordBaseAccess
56
- or
57
- // class Foo < ApplicationRecord
58
- this .getSuperclassExpr ( ) instanceof ApplicationRecordAccess
59
- or
60
44
// class Bar < Foo
61
- exists ( ActiveRecordModelClass other |
62
- other .getModule ( ) = resolveConstantReadAccess ( this .getSuperclassExpr ( ) )
63
- )
45
+ this .getSuperclassExpr ( ) =
46
+ [
47
+ API:: getTopLevelMember ( "ActiveRecord" ) .getMember ( "Base" ) ,
48
+ // In Rails applications `ApplicationRecord` typically extends `ActiveRecord::Base`, but we
49
+ // treat it separately in case the `ApplicationRecord` definition is not in the database.
50
+ API:: getTopLevelMember ( "ApplicationRecord" )
51
+ ] .getASubclass * ( ) .getAUse ( ) .asExpr ( ) .getExpr ( )
64
52
}
65
53
66
54
// Gets the class declaration for this class and all of its super classes
0 commit comments