@@ -7,31 +7,35 @@ module RuleGroups
7
7
8
8
included do
9
9
def save_rule_groups
10
- @rule_groups ||= @op_rule_groups . each_with_index . map do |op_rule_group , idx |
11
- ::RuleGroup . from_openscap_parser ( op_rule_group ,
12
- existing : old_rule_groups [ op_rule_group . id ] ,
13
- precedence : idx , benchmark_id : @benchmark &.id )
14
- end
15
-
16
- ::RuleGroup . import! ( new_rule_groups , ignore : true )
10
+ ::V2 ::RuleGroup . import! ( new_rule_groups , ignore : true )
17
11
18
12
# Overwite a superset of old_rule_groups because the IDs of the ancestors are not
19
13
# available in the first import! above
20
- ::RuleGroup . import ( rule_groups_with_ancestry , on_duplicate_key_update : {
21
- conflict_target : %i[ ref_id benchmark_id ] ,
22
- columns : %i[ description rationale precedence ancestry ]
23
- } , validate : false )
14
+ ::V2 :: RuleGroup . import ( rule_groups_with_ancestry , on_duplicate_key_update : {
15
+ conflict_target : %i[ ref_id security_guide_id ] ,
16
+ columns : %i[ description rationale precedence ancestry ]
17
+ } , validate : false )
24
18
end
25
19
26
20
private
27
21
22
+ def rule_groups
23
+ @rule_groups ||= @op_rule_groups . each_with_index . map do |op_rule_group , idx |
24
+ ::V2 ::RuleGroup . from_parser (
25
+ op_rule_group ,
26
+ existing : old_rule_groups [ op_rule_group . id ] , precedence : idx ,
27
+ security_guide_id : @security_guide . id
28
+ )
29
+ end
30
+ end
31
+
28
32
def new_rule_groups
29
- @new_rule_groups ||= @ rule_groups. select ( &:new_record? )
33
+ @new_rule_groups ||= rule_groups . select ( &:new_record? )
30
34
end
31
35
32
36
def old_rule_groups
33
- @old_rule_groups ||= ::RuleGroup . where (
34
- ref_id : @op_rule_groups . map ( &:id ) , benchmark : @benchmark & .id
37
+ @old_rule_groups ||= ::V2 :: RuleGroup . where (
38
+ ref_id : @op_rule_groups . map ( &:id ) , security_guide_id : @security_guide . id
35
39
) . index_by ( &:ref_id )
36
40
end
37
41
@@ -50,7 +54,7 @@ def rule_groups_with_ancestry
50
54
end
51
55
52
56
def rule_group_for ( ref_id :)
53
- @cached_rule_groups ||= @ rule_groups. index_by ( &:ref_id )
57
+ @cached_rule_groups ||= rule_groups . index_by ( &:ref_id )
54
58
@cached_rule_groups [ ref_id ]
55
59
end
56
60
end
0 commit comments