Class: Fig::Statement::Set

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

Overview

A statement that sets the value of an environment variable.

Constant Summary collapse

VALUE_REGEX =
%r< \A \S* \z >x
ARGUMENT_DESCRIPTION =
%q<The value must look like "NAME=VALUE", though VALUE can be empty.>

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) ⇒ Set

Returns a new instance of Set.



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

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.



27
28
29
# File 'lib/fig/statement/set.rb', line 27

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



27
28
29
# File 'lib/fig/statement/set.rb', line 27

def value
  @value
end

Class Method Details

.parse_name_value(combined) ⇒ Object

Yields on error.



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

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



36
37
38
# File 'lib/fig/statement/set.rb', line 36

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