Skip to content

Commit 24cd909

Browse files
author
Aryan Soni
committed
Extract callbacks from definition and document symbol into shared module
1 parent 679a494 commit 24cd909

File tree

4 files changed

+70
-114
lines changed

4 files changed

+70
-114
lines changed

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require "ruby_lsp/addon"
55

66
require_relative "support/active_support_test_case_helper"
7+
require_relative "support/callbacks"
78
require_relative "runner_client"
89
require_relative "hover"
910
require_relative "code_lens"

lib/ruby_lsp/ruby_lsp_rails/definition.rb

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,63 +26,7 @@ class Definition
2626
extend T::Sig
2727
include Requests::Support::Common
2828
include ActiveSupportTestCaseHelper
29-
30-
MODEL_CALLBACKS = T.let(
31-
[
32-
"before_validation",
33-
"after_validation",
34-
"before_save",
35-
"around_save",
36-
"after_save",
37-
"before_create",
38-
"around_create",
39-
"after_create",
40-
"after_commit",
41-
"after_rollback",
42-
"before_update",
43-
"around_update",
44-
"after_update",
45-
"before_destroy",
46-
"around_destroy",
47-
"after_destroy",
48-
"after_initialize",
49-
"after_find",
50-
"after_touch",
51-
].freeze,
52-
T::Array[String],
53-
)
54-
55-
CONTROLLER_CALLBACKS = T.let(
56-
[
57-
"after_action",
58-
"append_after_action",
59-
"append_around_action",
60-
"append_before_action",
61-
"around_action",
62-
"before_action",
63-
"prepend_after_action",
64-
"prepend_around_action",
65-
"prepend_before_action",
66-
"skip_after_action",
67-
"skip_around_action",
68-
"skip_before_action",
69-
].freeze,
70-
T::Array[String],
71-
)
72-
73-
JOB_CALLBACKS = T.let(
74-
[
75-
"after_enqueue",
76-
"after_perform",
77-
"around_enqueue",
78-
"around_perform",
79-
"before_enqueue",
80-
"before_perform",
81-
].freeze,
82-
T::Array[String],
83-
)
84-
85-
CALLBACKS = T.let((MODEL_CALLBACKS + CONTROLLER_CALLBACKS + JOB_CALLBACKS).freeze, T::Array[String])
29+
include Support::Callbacks
8630

8731
sig do
8832
params(

lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,63 +11,7 @@ class DocumentSymbol
1111
extend T::Sig
1212
include Requests::Support::Common
1313
include ActiveSupportTestCaseHelper
14-
15-
MODEL_CALLBACKS = T.let(
16-
[
17-
"before_validation",
18-
"after_validation",
19-
"before_save",
20-
"around_save",
21-
"after_save",
22-
"before_create",
23-
"around_create",
24-
"after_create",
25-
"after_commit",
26-
"after_rollback",
27-
"before_update",
28-
"around_update",
29-
"after_update",
30-
"before_destroy",
31-
"around_destroy",
32-
"after_destroy",
33-
"after_initialize",
34-
"after_find",
35-
"after_touch",
36-
].freeze,
37-
T::Array[String],
38-
)
39-
40-
CONTROLLER_CALLBACKS = T.let(
41-
[
42-
"after_action",
43-
"append_after_action",
44-
"append_around_action",
45-
"append_before_action",
46-
"around_action",
47-
"before_action",
48-
"prepend_after_action",
49-
"prepend_around_action",
50-
"prepend_before_action",
51-
"skip_after_action",
52-
"skip_around_action",
53-
"skip_before_action",
54-
].freeze,
55-
T::Array[String],
56-
)
57-
58-
JOB_CALLBACKS = T.let(
59-
[
60-
"after_enqueue",
61-
"after_perform",
62-
"around_enqueue",
63-
"around_perform",
64-
"before_enqueue",
65-
"before_perform",
66-
].freeze,
67-
T::Array[String],
68-
)
69-
70-
CALLBACKS = T.let((MODEL_CALLBACKS + CONTROLLER_CALLBACKS + JOB_CALLBACKS).freeze, T::Array[String])
14+
include Support::Callbacks
7115

7216
sig do
7317
params(
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module RubyLsp
5+
module Rails
6+
module Support
7+
module Callbacks
8+
MODEL_CALLBACKS = T.let(
9+
[
10+
"before_validation",
11+
"after_validation",
12+
"before_save",
13+
"around_save",
14+
"after_save",
15+
"before_create",
16+
"around_create",
17+
"after_create",
18+
"after_commit",
19+
"after_rollback",
20+
"before_update",
21+
"around_update",
22+
"after_update",
23+
"before_destroy",
24+
"around_destroy",
25+
"after_destroy",
26+
"after_initialize",
27+
"after_find",
28+
"after_touch",
29+
].freeze,
30+
T::Array[String],
31+
)
32+
33+
CONTROLLER_CALLBACKS = T.let(
34+
[
35+
"after_action",
36+
"append_after_action",
37+
"append_around_action",
38+
"append_before_action",
39+
"around_action",
40+
"before_action",
41+
"prepend_after_action",
42+
"prepend_around_action",
43+
"prepend_before_action",
44+
"skip_after_action",
45+
"skip_around_action",
46+
"skip_before_action",
47+
].freeze,
48+
T::Array[String],
49+
)
50+
51+
JOB_CALLBACKS = T.let(
52+
[
53+
"after_enqueue",
54+
"after_perform",
55+
"around_enqueue",
56+
"around_perform",
57+
"before_enqueue",
58+
"before_perform",
59+
].freeze,
60+
T::Array[String],
61+
)
62+
63+
CALLBACKS = T.let((MODEL_CALLBACKS + CONTROLLER_CALLBACKS + JOB_CALLBACKS).freeze, T::Array[String])
64+
end
65+
end
66+
end
67+
end

0 commit comments

Comments
 (0)