Sha256: 91b397bdba661b7882a66ddad8b7e8e95a1d0ae749b9a1fd20ce72117b233e0d

Contents?: true

Size: 949 Bytes

Versions: 4

Compression:

Stored size: 949 Bytes

Contents

require 'fig/statement'

module Fig; end

# A statement that specifies or modifies a path environment variable, e.g.
# "append", "path", "add" (though those are all synonyms).
class Fig::Statement::Path < Fig::Statement
  VALUE_REGEX          = %r< \A [^;:"<>|\s]+ \z >x
  ARGUMENT_DESCRIPTION =
    %q[The value must look like "NAME=VALUE". VALUE cannot contain any of ";:<>|", double quotes, or whitespace.]

  # Yields on error.
  def self.parse_name_value(combined)
    variable, value = combined.split("=")

    if variable !~ ENVIRONMENT_VARIABLE_NAME_REGEX
      yield
    end

    value = '' if value.nil?
    if value !~ VALUE_REGEX
      yield
    end

    return [variable, value]
  end

  attr_reader :name, :value

  def initialize(line_column, source_description, name, value)
    super(line_column, source_description)

    @name = name
    @value = value
  end

  def unparse(indent)
    "#{indent}append #{name}=#{value}"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fig-0.1.69 lib/fig/statement/path.rb
fig-0.1.67 lib/fig/statement/path.rb
fig-0.1.65 lib/fig/statement/path.rb
fig-0.1.64 lib/fig/statement/path.rb