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 #slice, #location, #unwrap, and other standard methods.
Dotenv files follow a simple format where each line is one of:
-
‘KEY=value` - Environment variable assignment
-
‘export 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.
-
#raw ⇒ String
readonly
The original raw line content.
-
#type ⇒ Symbol?
readonly
The line type (:assignment, :comment, :blank, :invalid).
-
#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).
Constructor Details
#initialize(raw, line_number) ⇒ EnvLine
Initialize a new EnvLine by parsing the raw content
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dotenv/merge/env_line.rb', line 64 def initialize(raw, line_number) @raw = raw @line_number = line_number @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.
58 59 60 |
# File 'lib/dotenv/merge/env_line.rb', line 58 def export @export end |
#key ⇒ String? (readonly)
Returns The environment variable key (for assignments).
52 53 54 |
# File 'lib/dotenv/merge/env_line.rb', line 52 def key @key end |
#line_number ⇒ Integer (readonly)
Returns The 1-indexed line number in the source file.
46 47 48 |
# File 'lib/dotenv/merge/env_line.rb', line 46 def line_number @line_number end |
#raw ⇒ String (readonly)
Returns The original raw line content.
43 44 45 |
# File 'lib/dotenv/merge/env_line.rb', line 43 def raw @raw end |
#type ⇒ Symbol? (readonly)
Returns The line type (:assignment, :comment, :blank, :invalid).
49 50 51 |
# File 'lib/dotenv/merge/env_line.rb', line 49 def type @type end |
#value ⇒ String? (readonly)
Returns The environment variable value (for assignments).
55 56 57 |
# File 'lib/dotenv/merge/env_line.rb', line 55 def value @value end |
Instance Method Details
#assignment? ⇒ Boolean
Check if this line is an environment variable assignment
95 96 97 |
# File 'lib/dotenv/merge/env_line.rb', line 95 def assignment? @type == :assignment end |
#blank? ⇒ Boolean
Check if this line is blank (empty or whitespace only)
109 110 111 |
# File 'lib/dotenv/merge/env_line.rb', line 109 def blank? @type == :blank end |
#comment ⇒ String?
Get the raw comment text (for comment lines only)
130 131 132 133 134 |
# File 'lib/dotenv/merge/env_line.rb', line 130 def comment return @raw if comment? nil end |
#comment? ⇒ Boolean
Check if this line is a comment
102 103 104 |
# File 'lib/dotenv/merge/env_line.rb', line 102 def comment? @type == :comment end |
#export? ⇒ Boolean
Check if this line has the export prefix
123 124 125 |
# File 'lib/dotenv/merge/env_line.rb', line 123 def export? @export end |
#inspect ⇒ String
Inspect for debugging
146 147 148 |
# File 'lib/dotenv/merge/env_line.rb', line 146 def inspect "#<#{self.class.name} line=#{@line_number} type=#{@type} key=#{@key.inspect}>" end |
#invalid? ⇒ Boolean
Check if this line is invalid (unparseable)
116 117 118 |
# File 'lib/dotenv/merge/env_line.rb', line 116 def invalid? @type == :invalid end |
#signature ⇒ Array<Symbol, String>?
Generate a unique signature for this line (used for merge matching)
86 87 88 89 90 |
# File 'lib/dotenv/merge/env_line.rb', line 86 def signature return unless @type == :assignment [:env, @key] end |
#to_s ⇒ String
Convert to string representation (returns raw content)
139 140 141 |
# File 'lib/dotenv/merge/env_line.rb', line 139 def to_s @raw end |