Class: KuberKit::EnvFileReader::Strategies::ArtifactFile::Parser
- Defined in:
- lib/kuber_kit/env_file_reader/strategies/artifact_file.rb
Overview
Parser is based on: https://github.com/bkeepers/dotenv/blob/master/lib/dotenv/parser.rb
Constant Summary collapse
- LINE =
/ (?:^|\A) # beginning of line \s* # leading whitespace (?:export\s+)? # optional export ([\w\.]+) # key (?:\s*=\s*?|:\s+?) # separator ( # optional value begin \s*'(?:\\'|[^'])*' # single quoted value | # or \s*"(?:\\"|[^"])*" # double quoted value | # or [^\#\r\n]+ # unquoted value )? # value end \s* # trailing whitespace (?:\#.*)? # optional comment (?:$|\z) # end of line /x
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(string, is_load = false) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(string, is_load = false) ⇒ Parser
Returns a new instance of Parser.
49 50 51 52 53 |
# File 'lib/kuber_kit/env_file_reader/strategies/artifact_file.rb', line 49 def initialize(string, is_load = false) @string = string @hash = {} @is_load = is_load end |
Class Method Details
.call(string, is_load = false) ⇒ Object
44 45 46 |
# File 'lib/kuber_kit/env_file_reader/strategies/artifact_file.rb', line 44 def call(string, is_load = false) new(string, is_load).call end |
Instance Method Details
#call ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/kuber_kit/env_file_reader/strategies/artifact_file.rb', line 55 def call # Convert line breaks to same format lines = @string.gsub(/\r\n?/, "\n") # Process matches lines.scan(LINE).each do |key, value| @hash[key] = parse_value(value || "") end @hash end |