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

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

Overview

This class is abstract.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ Base

: (Index index) -> void



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

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

: Index



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:

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

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

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



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:

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

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

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



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:

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

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

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



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:

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

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

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



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:

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

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

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



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



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



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



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



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



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:

~~~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



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:

~~~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



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:

~~~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



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:

~~~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



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:

~~~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



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

~~~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



278
279
280
# File 'lib/spoom/deadcode/plugins/base.rb', line 278

def on_send(send)
  # no-op
end