Class: Dotenv::Merge::EnvLine
- Inherits:
-
Ast::Merge::AstNode
- Object
- Ast::Merge::AstNode
- Dotenv::Merge::EnvLine
- Defined in:
- lib/dotenv/merge/env_line.rb
Overview
Represents a single line in a dotenv file.
Parses and categorizes lines as assignments, comments, blank lines, or invalid.
Inherits from Ast::Merge::AstNode for a normalized API across all ast-merge
content nodes. This provides TreeHaver::Node protocol compatibility including
#slice, #location, #unwrap, #type, #text, and other standard methods.
Dotenv files follow a simple format where each line is one of:
KEY=value- Environment variable assignmentexport KEY=value- Assignment with export prefix# comment- Comment line- Empty/whitespace - Blank line
Constant Summary collapse
- EXPORT_PREFIX =
Prefix for exported environment variables
"export "
Instance Attribute Summary collapse
-
#export ⇒ Boolean
readonly
Whether the line has an export prefix.
-
#key ⇒ String?
readonly
The environment variable key (for assignments).
-
#line_number ⇒ Integer
readonly
The 1-indexed line number in the source file.
-
#line_type ⇒ Symbol?
readonly
The line type (:assignment, :comment, :blank, :invalid).
-
#raw ⇒ String
readonly
The original raw line content.
-
#value ⇒ String?
readonly
The environment variable value (for assignments).
Instance Method Summary collapse
-
#assignment? ⇒ Boolean
Check if this line is an environment variable assignment.
-
#blank? ⇒ Boolean
Check if this line is blank (empty or whitespace only).
-
#comment ⇒ String?
Get the raw comment text (for comment lines only).
-
#comment? ⇒ Boolean
Check if this line is a comment.
-
#export? ⇒ Boolean
Check if this line has the export prefix.
-
#initialize(raw, line_number) ⇒ EnvLine
constructor
Initialize a new EnvLine by parsing the raw content.
-
#inspect ⇒ String
Inspect for debugging.
-
#invalid? ⇒ Boolean
Check if this line is invalid (unparseable).
-
#signature ⇒ Array<Symbol, String>?
Generate a unique signature for this line (used for merge matching).
-
#to_s ⇒ String
Convert to string representation (returns raw content).
-
#type ⇒ String
TreeHaver::Node protocol: type.
Constructor Details
#initialize(raw, line_number) ⇒ EnvLine
Initialize a new EnvLine by parsing the raw content
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dotenv/merge/env_line.rb', line 65 def initialize(raw, line_number) @raw = raw @line_number = line_number @line_type = nil @key = nil @value = nil @export = false parse! location = Ast::Merge::AstNode::Location.new( start_line: line_number, end_line: line_number, start_column: 0, end_column: @raw.length, ) super(slice: @raw, location: location) end |
Instance Attribute Details
#export ⇒ Boolean (readonly)
Returns Whether the line has an export prefix.
59 60 61 |
# File 'lib/dotenv/merge/env_line.rb', line 59 def export @export end |
#key ⇒ String? (readonly)
Returns The environment variable key (for assignments).
53 54 55 |
# File 'lib/dotenv/merge/env_line.rb', line 53 def key @key end |
#line_number ⇒ Integer (readonly)
Returns The 1-indexed line number in the source file.
47 48 49 |
# File 'lib/dotenv/merge/env_line.rb', line 47 def line_number @line_number end |
#line_type ⇒ Symbol? (readonly)
Returns The line type (:assignment, :comment, :blank, :invalid).
50 51 52 |
# File 'lib/dotenv/merge/env_line.rb', line 50 def line_type @line_type end |
#raw ⇒ String (readonly)
Returns The original raw line content.
44 45 46 |
# File 'lib/dotenv/merge/env_line.rb', line 44 def raw @raw end |
#value ⇒ String? (readonly)
Returns The environment variable value (for assignments).
56 57 58 |
# File 'lib/dotenv/merge/env_line.rb', line 56 def value @value end |
Instance Method Details
#assignment? ⇒ Boolean
Check if this line is an environment variable assignment
102 103 104 |
# File 'lib/dotenv/merge/env_line.rb', line 102 def assignment? @line_type == :assignment end |
#blank? ⇒ Boolean
Check if this line is blank (empty or whitespace only)
116 117 118 |
# File 'lib/dotenv/merge/env_line.rb', line 116 def blank? @line_type == :blank end |
#comment ⇒ String?
Get the raw comment text (for comment lines only)
137 138 139 140 141 |
# File 'lib/dotenv/merge/env_line.rb', line 137 def comment return @raw if comment? nil end |
#comment? ⇒ Boolean
Check if this line is a comment
109 110 111 |
# File 'lib/dotenv/merge/env_line.rb', line 109 def comment? @line_type == :comment end |
#export? ⇒ Boolean
Check if this line has the export prefix
130 131 132 |
# File 'lib/dotenv/merge/env_line.rb', line 130 def export? @export end |
#inspect ⇒ String
Inspect for debugging
153 154 155 |
# File 'lib/dotenv/merge/env_line.rb', line 153 def inspect "#<#{self.class.name} line=#{@line_number} line_type=#{@line_type} key=#{@key.inspect}>" end |
#invalid? ⇒ Boolean
Check if this line is invalid (unparseable)
123 124 125 |
# File 'lib/dotenv/merge/env_line.rb', line 123 def invalid? @line_type == :invalid end |
#signature ⇒ Array<Symbol, String>?
Generate a unique signature for this line (used for merge matching)
93 94 95 96 97 |
# File 'lib/dotenv/merge/env_line.rb', line 93 def signature return unless @line_type == :assignment [:env, @key] end |
#to_s ⇒ String
Convert to string representation (returns raw content)
146 147 148 |
# File 'lib/dotenv/merge/env_line.rb', line 146 def to_s @raw end |
#type ⇒ String
TreeHaver::Node protocol: type
86 87 88 |
# File 'lib/dotenv/merge/env_line.rb', line 86 def type "env_line" end |