Class: Rubyzen::Declarations::FileDeclaration
- Inherits:
-
Object
- Object
- Rubyzen::Declarations::FileDeclaration
- Includes:
- Providers::BlocksProvider, Providers::CallSiteProvider, Providers::ConstantsProvider, Providers::FilePathProvider, Providers::LineNumberProvider, Providers::LinesOfCodeProvider, Providers::RequiresProvider
- Defined in:
- lib/rubyzen/declarations/file_declaration.rb
Overview
Represents a parsed Ruby source file. This is the root of the declaration hierarchy — all other declarations are accessed through a FileDeclaration.
Instance Attribute Summary collapse
-
#node ⇒ RuboCop::AST::Node
(also: #ast)
readonly
The root AST node.
-
#path ⇒ String
readonly
Absolute path to the source file.
Instance Method Summary collapse
-
#classes ⇒ Array<ClassDeclaration>
Returns all classes defined in this file.
-
#initialize(path, ast) ⇒ FileDeclaration
constructor
A new instance of FileDeclaration.
-
#modules ⇒ Array<ModuleDeclaration>
Returns all modules defined in this file.
-
#name ⇒ String
Returns the basename of the file.
-
#top_level_module_name ⇒ String?
Returns the name of the first module in the file, used to determine the top-level namespace.
Methods included from Providers::BlocksProvider
Methods included from Providers::CallSiteProvider
Methods included from Providers::RequiresProvider
Methods included from Providers::ConstantsProvider
Methods included from Providers::LinesOfCodeProvider
Methods included from Providers::LineNumberProvider
Methods included from Providers::FilePathProvider
Constructor Details
#initialize(path, ast) ⇒ FileDeclaration
Returns a new instance of FileDeclaration.
30 31 32 33 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 30 def initialize(path, ast) @path = path @node = ast end |
Instance Attribute Details
#node ⇒ RuboCop::AST::Node (readonly) Also known as: ast
Returns the root AST node.
25 26 27 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 25 def node @node end |
#path ⇒ String (readonly)
Returns absolute path to the source file.
22 23 24 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 22 def path @path end |
Instance Method Details
#classes ⇒ Array<ClassDeclaration>
Returns all classes defined in this file.
45 46 47 48 49 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 45 def classes node.each_node(:class).map do |class_node| ClassDeclaration.new(class_node, self) end end |
#modules ⇒ Array<ModuleDeclaration>
Returns all modules defined in this file.
62 63 64 65 66 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 62 def modules node.each_node(:module).map do |module_node| Rubyzen::Declarations::ModuleDeclaration.new(module_node, self) end end |
#name ⇒ String
Returns the basename of the file.
38 39 40 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 38 def name File.basename(path) end |
#top_level_module_name ⇒ String?
Returns the name of the first module in the file, used to determine the top-level namespace.
55 56 57 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 55 def top_level_module_name modules.first&.name_without_modules end |