Class: MethodInfo::AncestorFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/method_info/ancestor_filter.rb

Overview

Utility class to filter a list of ancestors, taking the class/module hierarchy into account

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ancestors, options = {}) ⇒ AncestorFilter

Creates an AncestorFilter and performs a filtering based on the options passed.

Parameters

  • :include - An ancestor that is in this list and the original ancestor list will always be included, regardless of the value of :exclude.

  • :exclude - A list of ancestors that are to be excluded from the original list. If a class is excluded, all modules included under it are excluded as well.



13
14
15
16
# File 'lib/method_info/ancestor_filter.rb', line 13

def initialize(ancestors, options = {})
  @ancestors = ancestors
  filter(options)
end

Instance Attribute Details

#pickedObject (readonly)

A list of the ancestors that were picked by the filter



6
7
8
# File 'lib/method_info/ancestor_filter.rb', line 6

def picked
  @picked
end

Instance Method Details

#excludedObject

A list of the ancestors that were excluded by the filter



31
32
33
# File 'lib/method_info/ancestor_filter.rb', line 31

def excluded
  @ancestors - @picked
end

#filter(options = {}) ⇒ Object

Perform another filter operation on the same list of ancestors. See initialize for supported options.



20
21
22
23
24
25
26
27
28
# File 'lib/method_info/ancestor_filter.rb', line 20

def filter(options = {})
  @options = options
  @exclude = @options[:exclude] || []
  @include = @options[:include] || []
  @picked =
    @ancestors -
    (@exclude - included_ancestors) -
    (modules_under_excluded_classes - included_ancestors)
end