Sha256: b57b75dae427e99947dd450b20c9ed5c462b5042cfe28738fa4b36a38e6fb115

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'fig/statement'

module Fig; end

# A statement that sets the value of an environment variable.
class Fig::Statement::Set < Fig::Statement
  # We block quotes right now in order to allow for using them for
  # quoting later.
  VALUE_REGEX          = %r< \A [^\s\\'"]* \z >x
  ARGUMENT_DESCRIPTION =
    %q<The value must look like "NAME=VALUE"; VALUE cannot contain whitespace though it can be empty.>

  # 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 is_environment_variable?()
    return true
  end

  def unparse_as_version(unparser)
    return unparser.set(self)
  end

  def minimum_grammar_version_required()
    # TODO: fix this once going through
    # Statement.strip_quotes_and_process_escapes()
    return 0
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fig-0.1.77 lib/fig/statement/set.rb
fig-0.1.76 lib/fig/statement/set.rb
fig-0.1.75 lib/fig/statement/set.rb