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.
31 32 33 34 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 31 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.
26 27 28 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 26 def node @node end |
#path ⇒ String (readonly)
Returns absolute path to the source file.
23 24 25 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 23 def path @path end |
Instance Method Details
#classes ⇒ Array<ClassDeclaration>
Returns all classes defined in this file.
46 47 48 49 50 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 46 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.
63 64 65 66 67 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 63 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.
39 40 41 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 39 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.
56 57 58 |
# File 'lib/rubyzen/declarations/file_declaration.rb', line 56 def top_level_module_name modules.first&.name_without_modules end |