Class: Fig::Statement::Path

Inherits:
Fig::Statement show all
Defined in:
lib/fig/statement/path.rb

Overview

A statement that specifies or modifies a path environment variable, e.g. “append”, “path”, “add” (though those are all synonyms).

Constant Summary collapse

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.]

Constants inherited from Fig::Statement

ENVIRONMENT_VARIABLE_NAME_REGEX

Instance Attribute Summary collapse

Attributes inherited from Fig::Statement

#column, #line, #source_description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Fig::Statement

#is_asset?, position_description, #position_string, #urls, #walk_statements

Constructor Details

#initialize(line_column, source_description, name, value) ⇒ Path

Returns a new instance of Path.



30
31
32
33
34
35
# File 'lib/fig/statement/path.rb', line 30

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

  @name = name
  @value = value
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/fig/statement/path.rb', line 28

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



28
29
30
# File 'lib/fig/statement/path.rb', line 28

def value
  @value
end

Class Method Details

.parse_name_value(combined) ⇒ Object

Yields on error.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fig/statement/path.rb', line 13

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

Instance Method Details

#unparse(indent) ⇒ Object



37
38
39
# File 'lib/fig/statement/path.rb', line 37

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