Class: Spoom::Deadcode::Plugins::Base

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers
Defined in:
lib/spoom/deadcode/plugins/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ Base

: (Index index) -> void



129
130
131
# File 'lib/spoom/deadcode/plugins/base.rb', line 129

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

: Index



126
127
128
# File 'lib/spoom/deadcode/plugins/base.rb', line 126

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

ignore_classes_inheriting_from(
  "Foo",
  "Bar",
  /Baz.*/,
)

end ~~~ : (*(String | Regexp) names) -> void



49
50
51
# File 'lib/spoom/deadcode/plugins/base.rb', line 49

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

ignore_class_names(
  "Foo",
  "Bar",
  /Baz.*/,
)

end ~~~ : (*(String | Regexp) names) -> void



31
32
33
# File 'lib/spoom/deadcode/plugins/base.rb', line 31

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

ignore_class_names(
  "FOO",
  "BAR",
  /BAZ.*/,
)

end ~~~ : (*(String | Regexp) names) -> void



67
68
69
# File 'lib/spoom/deadcode/plugins/base.rb', line 67

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

ignore_method_names(
  "foo",
  "bar",
  /baz.*/,
)

end ~~~ : (*(String | Regexp) names) -> void



85
86
87
# File 'lib/spoom/deadcode/plugins/base.rb', line 85

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

ignore_class_names(
  "Foo",
  "Bar",
  /Baz.*/,
)

end ~~~ : (*(String | Regexp) names) -> void



103
104
105
# File 'lib/spoom/deadcode/plugins/base.rb', line 103

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. : (Model::Attr definition) -> void



155
156
157
# File 'lib/spoom/deadcode/plugins/base.rb', line 155

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. : (Model::Class definition) -> void



179
180
181
182
183
184
185
186
187
# File 'lib/spoom/deadcode/plugins/base.rb', line 179

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. : (Model::Constant definition) -> void



209
210
211
212
213
# File 'lib/spoom/deadcode/plugins/base.rb', line 209

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. : (Model::Method definition) -> void



235
236
237
238
239
# File 'lib/spoom/deadcode/plugins/base.rb', line 235

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. : (Model::Module definition) -> void



261
262
263
264
265
# File 'lib/spoom/deadcode/plugins/base.rb', line 261

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

def on_define_accessor(definition)
  @index.ignore(definition) if symbol_def.name == "foo"
end

end ~~~ : (Model::Attr definition) -> void



149
150
151
# File 'lib/spoom/deadcode/plugins/base.rb', line 149

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

def on_define_class(definition)
  @index.ignore(definition) if definition.name == "Foo"
end

end ~~~ : (Model::Class definition) -> void



173
174
175
# File 'lib/spoom/deadcode/plugins/base.rb', line 173

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

def on_define_constant(definition)
  @index.ignore(definition) if definition.name == "FOO"
end

end ~~~ : (Model::Constant definition) -> void



203
204
205
# File 'lib/spoom/deadcode/plugins/base.rb', line 203

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

def on_define_method(definition)
  @index.ignore(definition) if definition.name == "foo"
end

end ~~~ : (Model::Method definition) -> void



229
230
231
# File 'lib/spoom/deadcode/plugins/base.rb', line 229

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:

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

def on_define_module(definition)
  @index.ignore(definition) if definition.name == "Foo"
end

end ~~~ : (Model::Module definition) -> void



255
256
257
# File 'lib/spoom/deadcode/plugins/base.rb', line 255

def on_define_module(definition)
  # no-op
end

#on_send(send) ⇒ Object

Called when a send is being processed

~~~rb class MyPlugin < Spoom::Deadcode::Plugins::Base

def on_send(send)
  return unless send.name == "dsl_method"
  return if send.args.empty?

  method_name = send.args.first.slice.delete_prefix(":")
  @index.reference_method(method_name, send.node, send.loc)
end

end ~~~ : (Send send) -> void



281
282
283
# File 'lib/spoom/deadcode/plugins/base.rb', line 281

def on_send(send)
  # no-op
end