Class: Rubyzen::Declarations::RequireDeclaration
- Inherits:
-
Object
- Object
- Rubyzen::Declarations::RequireDeclaration
- Defined in:
- lib/rubyzen/declarations/require_declaration.rb
Overview
Represents a require, require_relative, or load statement.
Instance Attribute Summary collapse
- #node ⇒ RuboCop::AST::Node readonly
- #parent_file ⇒ FileDeclaration (also: #parent) readonly
Instance Method Summary collapse
-
#initialize(node, parent_file) ⇒ RequireDeclaration
constructor
A new instance of RequireDeclaration.
- #load? ⇒ Boolean
-
#name ⇒ String
Returns the statement type.
- #require? ⇒ Boolean
- #require_relative? ⇒ Boolean
-
#required_path ⇒ String?
Returns the required path string.
Methods included from Providers::LineNumberProvider
Methods included from Providers::FilePathProvider
Constructor Details
#initialize(node, parent_file) ⇒ RequireDeclaration
Returns a new instance of RequireDeclaration.
24 25 26 27 |
# File 'lib/rubyzen/declarations/require_declaration.rb', line 24 def initialize(node, parent_file) @node = node @parent_file = parent_file end |
Instance Attribute Details
#node ⇒ RuboCop::AST::Node (readonly)
16 17 18 |
# File 'lib/rubyzen/declarations/require_declaration.rb', line 16 def node @node end |
#parent_file ⇒ FileDeclaration (readonly) Also known as: parent
19 20 21 |
# File 'lib/rubyzen/declarations/require_declaration.rb', line 19 def parent_file @parent_file end |
Instance Method Details
#load? ⇒ Boolean
56 57 58 |
# File 'lib/rubyzen/declarations/require_declaration.rb', line 56 def load? name == 'load' end |
#name ⇒ String
Returns the statement type.
32 33 34 |
# File 'lib/rubyzen/declarations/require_declaration.rb', line 32 def name node.method_name.to_s end |
#require? ⇒ Boolean
46 47 48 |
# File 'lib/rubyzen/declarations/require_declaration.rb', line 46 def require? name == 'require' end |
#require_relative? ⇒ Boolean
51 52 53 |
# File 'lib/rubyzen/declarations/require_declaration.rb', line 51 def require_relative? name == 'require_relative' end |
#required_path ⇒ String?
Returns the required path string.
39 40 41 42 43 |
# File 'lib/rubyzen/declarations/require_declaration.rb', line 39 def required_path first_arg = node.arguments.first return nil unless first_arg&.type == :str first_arg.value end |