Module: SorbetRails::ModelPlugins

Extended by:
T::Sig
Includes:
Kernel
Included in:
ModelRbiFormatter
Defined in:
lib/sorbet-rails/model_plugins/base.rb,
lib/sorbet-rails/model_plugins/plugins.rb

Defined Under Namespace

Classes: ActiveRecordAssoc, ActiveRecordAttribute, ActiveRecordEnum, ActiveRecordNamedScope, ActiveRecordQuerying, ActiveRecordSerializedAttribute, ActiveRelationWhereNot, ActiveStorageMethods, Base, CustomFinderMethods, EnumerableCollections, UnrecognizedPluginName

Constant Summary collapse

@@plugins =
T.let([], T::Array[T.class_of(Base)])

Instance Method Summary collapse

Instance Method Details

#get_plugin_by_name(plugin_name) ⇒ Object


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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/sorbet-rails/model_plugins/plugins.rb', line 41

def get_plugin_by_name(plugin_name)
  case plugin_name
  when :active_record_enum
    ActiveRecordEnum
  when :active_record_named_scope
    ActiveRecordNamedScope
  when :active_record_querying
    ActiveRecordQuerying
  when :active_relation_where_not
    ActiveRelationWhereNot
  when :active_record_serialized_attribute
    ActiveRecordSerializedAttribute
  when :active_record_attribute
    ActiveRecordAttribute
  when :active_record_assoc
    ActiveRecordAssoc
  when :custom_finder_methods
    CustomFinderMethods
  when :enumerable_collections
    EnumerableCollections
  when :active_storage_methods
    ActiveStorageMethods
  when :kaminari
    require('sorbet-rails/gem_plugins/kaminari_plugin')
    KaminariPlugin
  when :pg_search
    require('sorbet-rails/gem_plugins/pg_search_plugin')
    PgSearchPlugin
  when :friendly_id
    require('sorbet-rails/gem_plugins/friendly_id_plugin')
    FriendlyIdPlugin
  when :shrine
    require('sorbet-rails/gem_plugins/shrine_plugin')
    ShrinePlugin
  when :elastic_search
    require('sorbet-rails/gem_plugins/elastic_search_plugin')
    ElasticSearchPlugin
  when :active_flag
    require('sorbet-rails/gem_plugins/active_flag_plugin')
    ActiveFlagPlugin
  when :paperclip
    require('sorbet-rails/gem_plugins/paperclip_plugin')
    PaperclipPlugin
  when :attr_json
    require('sorbet-rails/gem_plugins/attr_json_plugin')
    AttrJsonPlugin
  when :flag_shih_tzu
    require('sorbet-rails/gem_plugins/flag_shih_tzu_plugin')
    FlagShihTzuPlugin
  else
    raise UnrecognizedPluginName.new(
      "Unrecognized plugin with name: #{plugin_name}. Please check available plugins in the
      documentation".squish!
    )
  end
end

#get_pluginsObject


31
32
33
# File 'lib/sorbet-rails/model_plugins/plugins.rb', line 31

def get_plugins
  @@plugins
end

#register_plugin(plugin) ⇒ Object


21
22
23
# File 'lib/sorbet-rails/model_plugins/plugins.rb', line 21

def register_plugin(plugin)
  @@plugins.push(plugin) unless @@plugins.include?(plugin)
end

#register_plugin_by_name(plugin_name) ⇒ Object


36
37
38
# File 'lib/sorbet-rails/model_plugins/plugins.rb', line 36

def register_plugin_by_name(plugin_name)
  register_plugin(get_plugin_by_name(plugin_name))
end

#set_plugins(plugins) ⇒ Object


26
27
28
# File 'lib/sorbet-rails/model_plugins/plugins.rb', line 26

def set_plugins(plugins)
  @@plugins = plugins
end