Class: Rubyzen::Collections::ClassesCollection
- Inherits:
-
BaseCollection
- Object
- Array
- BaseCollection
- Rubyzen::Collections::ClassesCollection
- Includes:
- Providers::CollectionFilterProvider
- Defined in:
- lib/rubyzen/collections/classes_collection.rb
Overview
Collection of class declarations with methods for navigating into child elements (methods, attributes, macros) and filtering by inheritance.
Instance Method Summary collapse
-
#+(other) ⇒ ClassesCollection
Merges two ClassesCollections into a new ClassesCollection.
-
#all_methods ⇒ MethodsCollection
Returns all instance and class methods across every class in the collection.
-
#attributes ⇒ AttributesCollection
Returns all attribute declarations across every class.
-
#macros ⇒ MacrosCollection
Returns all macro invocations across every class.
-
#raises ⇒ RaisesCollection
Returns all raise declarations across every class.
-
#rescues ⇒ RescuesCollection
Returns all rescue declarations across every class.
-
#with_macro_name(macro_name) ⇒ ClassesCollection
Filters classes that contain at least one macro with the given name.
-
#with_parent_prefix(prefix) ⇒ ClassesCollection
Filters classes whose superclass starts with the given prefix.
Methods included from Providers::CollectionFilterProvider
#with_name, #with_name_ending_with, #with_name_including, #with_name_starting_with, #without_name, #without_name_ending_with, #without_name_including, #without_name_starting_with
Methods inherited from BaseCollection
Instance Method Details
#+(other) ⇒ ClassesCollection
Merges two ClassesCollections into a new ClassesCollection.
71 72 73 74 |
# File 'lib/rubyzen/collections/classes_collection.rb', line 71 def +(other) merged = super(other) self.class.new(merged) end |
#all_methods ⇒ MethodsCollection
Returns all instance and class methods across every class in the collection.
14 15 16 17 |
# File 'lib/rubyzen/collections/classes_collection.rb', line 14 def all_methods instance_plus_class_methods = flat_map { |klass| klass.instance_methods + klass.class_methods } MethodsCollection.new(instance_plus_class_methods) end |
#attributes ⇒ AttributesCollection
Returns all attribute declarations across every class.
22 23 24 25 |
# File 'lib/rubyzen/collections/classes_collection.rb', line 22 def attributes all_attributes = flat_map(&:attributes) AttributesCollection.new(all_attributes) end |
#macros ⇒ MacrosCollection
Returns all macro invocations across every class.
30 31 32 33 |
# File 'lib/rubyzen/collections/classes_collection.rb', line 30 def macros all_macros = flat_map(&:macros) MacrosCollection.new(all_macros) end |
#raises ⇒ RaisesCollection
Returns all raise declarations across every class.
46 47 48 49 |
# File 'lib/rubyzen/collections/classes_collection.rb', line 46 def raises all_raises = flat_map(&:raises) RaisesCollection.new(all_raises) end |
#rescues ⇒ RescuesCollection
Returns all rescue declarations across every class.
38 39 40 41 |
# File 'lib/rubyzen/collections/classes_collection.rb', line 38 def rescues all_rescues = flat_map(&:rescues) RescuesCollection.new(all_rescues) end |
#with_macro_name(macro_name) ⇒ ClassesCollection
Filters classes that contain at least one macro with the given name.
63 64 65 |
# File 'lib/rubyzen/collections/classes_collection.rb', line 63 def with_macro_name(macro_name) filter { |klass| klass.macros.with_name(macro_name).any? } end |
#with_parent_prefix(prefix) ⇒ ClassesCollection
Filters classes whose superclass starts with the given prefix.
55 56 57 |
# File 'lib/rubyzen/collections/classes_collection.rb', line 55 def with_parent_prefix(prefix) filter { |klass| klass.superclass_prefix?(prefix) } end |