Class: Rubyzen::Collections::FileCollection

Inherits:
BaseCollection show all
Includes:
Providers::CollectionFilterProvider
Defined in:
lib/rubyzen/collections/file_collection.rb

Overview

Collection of parsed file declarations. Serves as the top-level entry point for navigating into classes, modules, constants, and other code elements.

Examples:

Getting all controller classes

project.files.with_paths('src/controllers/').classes

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

#blocksBlocksCollection

Returns all block declarations across every file.

Returns:



75
76
77
78
# File 'lib/rubyzen/collections/file_collection.rb', line 75

def blocks
  all_blocks = flat_map(&:blocks)
  BlocksCollection.new(all_blocks)
end

#call_sitesCallSiteCollection

Returns all call sites across every file.

Returns:



67
68
69
70
# File 'lib/rubyzen/collections/file_collection.rb', line 67

def call_sites
  all_call_sites = flat_map(&:call_sites)
  CallSiteCollection.new(all_call_sites)
end

#classesClassesCollection

Returns all class declarations across every file.

Returns:



35
36
37
38
# File 'lib/rubyzen/collections/file_collection.rb', line 35

def classes
  all_classes = flat_map(&:classes)
  ClassesCollection.new(all_classes)
end

#constantsConstantsCollection

Returns all constant declarations across every file.

Returns:



51
52
53
54
# File 'lib/rubyzen/collections/file_collection.rb', line 51

def constants
  all_constants = flat_map(&:constants)
  ConstantsCollection.new(all_constants)
end

#modulesModulesCollection

Returns all module declarations across every file.

Returns:



43
44
45
46
# File 'lib/rubyzen/collections/file_collection.rb', line 43

def modules
  all_modules = flat_map(&:modules)
  ModulesCollection.new(all_modules)
end

#requiresRequiresCollection

Returns all require/require_relative/load statements across every file.

Returns:



59
60
61
62
# File 'lib/rubyzen/collections/file_collection.rb', line 59

def requires
  all_requires = flat_map(&:requires)
  RequiresCollection.new(all_requires)
end

#with_paths(*paths) ⇒ FileCollection

Filters files whose path includes any of the given substrings.

Parameters:

  • paths (Array<String>)

    path substrings to match

Returns:



16
17
18
19
20
# File 'lib/rubyzen/collections/file_collection.rb', line 16

def with_paths(*paths)
  filter do |file_declaration|
    paths.any? { |p| file_declaration.path.include?(p) }
  end
end

#without_paths(*paths) ⇒ FileCollection

Excludes files whose path includes any of the given substrings.

Parameters:

  • paths (Array<String>)

    path substrings to exclude

Returns:



26
27
28
29
30
# File 'lib/rubyzen/collections/file_collection.rb', line 26

def without_paths(*paths)
  filter do |file_declaration|
    !paths.any? { |p| file_declaration.path.include?(p) }
  end
end