Class: Rubyzen::Collections::ClassesCollection

Inherits:
BaseCollection show all
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.

Examples:

Ensuring controllers inherit from ApplicationController

expect(controllers.with_parent_prefix('ApplicationController')).not_to zen_empty

Instance Method Summary collapse

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

#filter

Instance Method Details

#+(other) ⇒ ClassesCollection

Merges two ClassesCollections into a new ClassesCollection.

Parameters:

Returns:



71
72
73
74
# File 'lib/rubyzen/collections/classes_collection.rb', line 71

def +(other)
  merged = super(other)
  self.class.new(merged)
end

#all_methodsMethodsCollection

Returns all instance and class methods across every class in the collection.

Returns:



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

#attributesAttributesCollection

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

#macrosMacrosCollection

Returns all macro invocations across every class.

Returns:



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

#raisesRaisesCollection

Returns all raise declarations across every class.

Returns:



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

#rescuesRescuesCollection

Returns all rescue declarations across every class.

Returns:



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.

Parameters:

  • macro_name (String)

    the macro name to search for

Returns:



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.

Parameters:

  • prefix (String)

    the superclass name prefix to match

Returns:



55
56
57
# File 'lib/rubyzen/collections/classes_collection.rb', line 55

def with_parent_prefix(prefix)
  filter { |klass| klass.superclass_prefix?(prefix) }
end