This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
/
config.rb
74 lines (61 loc) · 1.94 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# typed: true
require("sorbet-rails/mailer_rbi_formatter")
require("sorbet-rails/job_rbi_formatter")
module SorbetRails
class << self
extend T::Sig
sig { params(blk: T.proc.params(arg0: Config).void).void }
def configure(&blk)
yield config
# After user has configured, register any plugins the user has added to
# their configuration.
register_configured_plugins
end
sig { returns(Config) }
def config
@_config ||= Config.new
end
sig { void }
def register_configured_plugins
config.enabled_plugins.each do |plugin_name|
SorbetRails::ModelRbiFormatter.register_plugin_by_name(plugin_name)
end
end
end
class Config
extend T::Sig
sig { returns(T::Array[Symbol]) }
attr_accessor :enabled_gem_plugins
sig { returns(T::Array[Symbol]) }
attr_accessor :enabled_model_plugins
sig { returns(T::Array[String]) }
attr_accessor :extra_helper_includes
sig { returns(T.class_of(SorbetRails::JobRbiFormatter))}
attr_accessor :job_generator_class
sig { returns(T.class_of(SorbetRails::MailerRbiFormatter))}
attr_accessor :mailer_generator_class
sig { void }
def initialize
@enabled_gem_plugins = []
@enabled_model_plugins = [
:active_record_enum,
:active_record_named_scope,
:active_record_querying,
:active_relation_where_not,
:active_record_serialized_attribute,
:active_record_attribute,
:active_record_assoc,
:custom_finder_methods,
:enumerable_collections,
]
@enabled_model_plugins << :active_storage_methods if defined?(T.unsafe(ActiveStorage))
@extra_helper_includes = []
@mailer_generator_class = SorbetRails::MailerRbiFormatter
@job_generator_class = SorbetRails::JobRbiFormatter
end
sig { returns(T::Array[Symbol]) }
def enabled_plugins
@enabled_model_plugins + @enabled_gem_plugins
end
end
end