Class: Spoom::Deadcode::Plugins::Base Abstract
- Inherits:
-
Object
- Object
- Spoom::Deadcode::Plugins::Base
- Defined in:
- lib/spoom/deadcode/plugins/base.rb
Overview
Direct Known Subclasses
ActionMailer, ActionMailerPreview, ActionPack, ActiveJob, ActiveModel, ActiveRecord, ActiveSupport, GraphQL, Minitest, Namespaces, RSpec, Rails, Rake, Rubocop, Ruby, Sorbet, Thor
Instance Attribute Summary collapse
- #index ⇒ Object readonly
Class Method Summary collapse
-
.ignore_classes_inheriting_from(*names) ⇒ Object
Mark classes directly subclassing a class matching
namesas ignored. -
.ignore_classes_named(*names) ⇒ Object
Mark classes matching
namesas ignored. -
.ignore_constants_named(*names) ⇒ Object
Mark constants matching
namesas ignored. -
.ignore_methods_named(*names) ⇒ Object
Mark methods matching
namesas ignored. -
.ignore_modules_named(*names) ⇒ Object
Mark modules matching
namesas ignored.
Instance Method Summary collapse
-
#initialize(index) ⇒ Base
constructor
A new instance of Base.
-
#internal_on_define_accessor(definition) ⇒ Object
Do not override this method, use
on_define_accessorinstead. -
#internal_on_define_class(definition) ⇒ Object
Do not override this method, use
on_define_classinstead. -
#internal_on_define_constant(definition) ⇒ Object
Do not override this method, use
on_define_constantinstead. -
#internal_on_define_method(definition) ⇒ Object
Do not override this method, use
on_define_methodinstead. -
#internal_on_define_module(definition) ⇒ Object
Do not override this method, use
on_define_moduleinstead. -
#on_define_accessor(definition) ⇒ Object
Called when an accessor is defined.
-
#on_define_class(definition) ⇒ Object
Called when a class is defined.
-
#on_define_constant(definition) ⇒ Object
Called when a constant is defined.
-
#on_define_method(definition) ⇒ Object
Called when a method is defined.
-
#on_define_module(definition) ⇒ Object
Called when a module is defined.
-
#on_send(send) ⇒ Object
Called when a send is being processed.
Constructor Details
#initialize(index) ⇒ Base
Returns a new instance of Base.
126 127 128 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 126 def initialize(index) @index = index end |
Instance Attribute Details
#index ⇒ Object (readonly)
123 124 125 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 123 def index @index end |
Class Method Details
.ignore_classes_inheriting_from(*names) ⇒ Object
Mark classes directly subclassing a class matching names as ignored.
Names can be either strings or regexps:
class MyPlugin < Spoom::Deadcode::Plugins::Base
ignore_classes_inheriting_from(
"Foo",
"Bar",
/Baz.*/,
)
end
46 47 48 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 46 def ignore_classes_inheriting_from(*names) save_names_and_patterns(names, :@ignored_subclasses_of_names, :@ignored_subclasses_of_patterns) end |
.ignore_classes_named(*names) ⇒ Object
Mark classes matching names as ignored.
Names can be either strings or regexps:
class MyPlugin < Spoom::Deadcode::Plugins::Base
ignore_class_names(
"Foo",
"Bar",
/Baz.*/,
)
end
28 29 30 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 28 def ignore_classes_named(*names) save_names_and_patterns(names, :@ignored_class_names, :@ignored_class_patterns) end |
.ignore_constants_named(*names) ⇒ Object
Mark constants matching names as ignored.
Names can be either strings or regexps:
class MyPlugin < Spoom::Deadcode::Plugins::Base
ignore_class_names(
"FOO",
"BAR",
/BAZ.*/,
)
end
64 65 66 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 64 def ignore_constants_named(*names) save_names_and_patterns(names, :@ignored_constant_names, :@ignored_constant_patterns) end |
.ignore_methods_named(*names) ⇒ Object
Mark methods matching names as ignored.
Names can be either strings or regexps:
class MyPlugin < Spoom::Deadcode::Plugins::Base
ignore_method_names(
"foo",
"bar",
/baz.*/,
)
end
82 83 84 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 82 def ignore_methods_named(*names) save_names_and_patterns(names, :@ignored_method_names, :@ignored_method_patterns) end |
.ignore_modules_named(*names) ⇒ Object
Mark modules matching names as ignored.
Names can be either strings or regexps:
class MyPlugin < Spoom::Deadcode::Plugins::Base
ignore_class_names(
"Foo",
"Bar",
/Baz.*/,
)
end
100 101 102 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 100 def ignore_modules_named(*names) save_names_and_patterns(names, :@ignored_module_names, :@ignored_module_patterns) end |
Instance Method Details
#internal_on_define_accessor(definition) ⇒ Object
Do not override this method, use on_define_accessor instead.
152 153 154 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 152 def internal_on_define_accessor(definition) on_define_accessor(definition) end |
#internal_on_define_class(definition) ⇒ Object
Do not override this method, use on_define_class instead.
176 177 178 179 180 181 182 183 184 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 176 def internal_on_define_class(definition) if ignored_class_name?(definition.name) @index.ignore(definition) elsif ignored_subclass?(definition) @index.ignore(definition) end on_define_class(definition) end |
#internal_on_define_constant(definition) ⇒ Object
Do not override this method, use on_define_constant instead.
206 207 208 209 210 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 206 def internal_on_define_constant(definition) @index.ignore(definition) if ignored_constant_name?(definition.name) on_define_constant(definition) end |
#internal_on_define_method(definition) ⇒ Object
Do not override this method, use on_define_method instead.
232 233 234 235 236 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 232 def internal_on_define_method(definition) @index.ignore(definition) if ignored_method_name?(definition.name) on_define_method(definition) end |
#internal_on_define_module(definition) ⇒ Object
Do not override this method, use on_define_module instead.
258 259 260 261 262 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 258 def internal_on_define_module(definition) @index.ignore(definition) if ignored_module_name?(definition.name) on_define_module(definition) end |
#on_define_accessor(definition) ⇒ Object
Called when an accessor is defined.
Will be called when the indexer processes a attr_reader, attr_writer or attr_accessor node.
Note that when this method is called, the definition for the node has already been added to the index.
It is still possible to ignore it from the plugin:
class MyPlugin < Spoom::Deadcode::Plugins::Base
def on_define_accessor(definition)
@index.ignore(definition) if symbol_def.name == "foo"
end
end
146 147 148 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 146 def on_define_accessor(definition) # no-op end |
#on_define_class(definition) ⇒ Object
Called when a class is defined.
Will be called when the indexer processes a class node.
Note that when this method is called, the definition for the node has already been added to the index.
It is still possible to ignore it from the plugin:
class MyPlugin < Spoom::Deadcode::Plugins::Base
def on_define_class(definition)
@index.ignore(definition) if definition.name == "Foo"
end
end
170 171 172 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 170 def on_define_class(definition) # no-op end |
#on_define_constant(definition) ⇒ Object
Called when a constant is defined.
Will be called when the indexer processes a CONST = node.
Note that when this method is called, the definition for the node has already been added to the index.
It is still possible to ignore it from the plugin:
class MyPlugin < Spoom::Deadcode::Plugins::Base
def on_define_constant(definition)
@index.ignore(definition) if definition.name == "FOO"
end
end
200 201 202 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 200 def on_define_constant(definition) # no-op end |
#on_define_method(definition) ⇒ Object
Called when a method is defined.
Will be called when the indexer processes a def or defs node.
Note that when this method is called, the definition for the node has already been added to the index.
It is still possible to ignore it from the plugin:
class MyPlugin < Spoom::Deadcode::Plugins::Base
def on_define_method(definition)
@index.ignore(definition) if definition.name == "foo"
end
end
226 227 228 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 226 def on_define_method(definition) # no-op end |
#on_define_module(definition) ⇒ Object
Called when a module is defined.
Will be called when the indexer processes a module node.
Note that when this method is called, the definition for the node has already been added to the index.
It is still possible to ignore it from the plugin:
class MyPlugin < Spoom::Deadcode::Plugins::Base
def on_define_module(definition)
@index.ignore(definition) if definition.name == "Foo"
end
end
252 253 254 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 252 def on_define_module(definition) # no-op end |
#on_send(send) ⇒ Object
Called when a send is being processed
class MyPlugin < Spoom::Deadcode::Plugins::Base
def on_send(send)
return unless send.name == "dsl_method"
arg = send.args.first
return unless arg.is_a?(Prism::SymbolNode)
@index.reference_method(arg.unescaped, send.node, send.loc)
end
end
279 280 281 |
# File 'lib/spoom/deadcode/plugins/base.rb', line 279 def on_send(send) # no-op end |