Class: MethodInfo::AncestorFilter
- 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
-
#picked ⇒ Object
readonly
A list of the ancestors that were picked by the filter.
Instance Method Summary collapse
-
#excluded ⇒ Object
A list of the ancestors that were excluded by the filter.
-
#filter(options = {}) ⇒ Object
Perform another filter operation on the same list of ancestors.
-
#initialize(ancestors, options = {}) ⇒ AncestorFilter
constructor
Creates an AncestorFilter and performs a filtering based on the options passed.
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, = {}) @ancestors = ancestors filter() end |
Instance Attribute Details
#picked ⇒ Object (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
#excluded ⇒ Object
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 = @exclude = @options[:exclude] || [] @include = @options[:include] || [] @picked = @ancestors - (@exclude - included_ancestors) - (modules_under_excluded_classes - included_ancestors) end |