Class: Fig::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/statement.rb,
lib/fig/statement/asset.rb,
lib/fig/statement/archive.rb,
lib/fig/statement/resource.rb

Overview

A statement within a package definition file (package.fig).

Defined Under Namespace

Modules: Asset Classes: Archive, Command, Configuration, GrammarVersion, Include, Override, Path, Resource, Retrieve, Set

Constant Summary collapse

ENVIRONMENT_VARIABLE_NAME_REGEX =
%r< \A \w+ \z >x

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line_column, source_description) ⇒ Statement

This mess of getting these as a single array necessary is due to limitations of the “*” array splat operator in ruby v1.8.



146
147
148
149
150
151
152
# File 'lib/fig/statement.rb', line 146

def initialize(line_column, source_description)
  if line_column
    @line, @column = *line_column
  end

  @source_description = source_description
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



11
12
13
# File 'lib/fig/statement.rb', line 11

def column
  @column
end

#lineObject (readonly)

Returns the value of attribute line.



11
12
13
# File 'lib/fig/statement.rb', line 11

def line
  @line
end

#source_descriptionObject (readonly)

Returns the value of attribute source_description.



11
12
13
# File 'lib/fig/statement.rb', line 11

def source_description
  @source_description
end

Class Method Details

.position_description(line, column, source_description) ⇒ Object



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

def self.position_description(line, column, source_description)
  if not line or not column
    return '' if not source_description

    return " (#{source_description})"
  end

  description = " (line #{line}, column #{column}"
  if source_description
    description << ", #{source_description}"
  end
  description << ')'

  return description
end

.strip_quotes_and_process_escapes!(string, &error_block) ⇒ Object

Parameter will be modified.

Takes a block that is invoked when there is an error. Block receives a single parameter of an error message that is the end of a statement describing the problem, with no leading space character. For example, given «‘foo», the block will receive a message like ’has unbalanced single quotes.‘.

Returns whether parameter was single-quoted; if there was a parse error, then the return value will be nil (and the block will have been invoked).



39
40
41
42
43
44
45
46
47
# File 'lib/fig/statement.rb', line 39

def self.strip_quotes_and_process_escapes!(string, &error_block)
  return false if string.length == 0

  replaced_quotes = strip_single_quotes!(string, &error_block)
  return true if replaced_quotes
  return      if replaced_quotes.nil?

  return process_escapes_and_strip_double_quotes!(string, &error_block)
end

Instance Method Details

#is_asset?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/fig/statement.rb', line 171

def is_asset?()
  return false
end

#is_environment_variable?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/fig/statement.rb', line 175

def is_environment_variable?()
  return false
end

#minimum_grammar_version_requiredObject

Raises:

  • (NotImplementedError)


163
164
165
# File 'lib/fig/statement.rb', line 163

def minimum_grammar_version_required()
  raise NotImplementedError
end

#position_stringObject

Returns a representation of the position of this statement, if the position is known, empty string otherwise. This is written with the idea that you can do something like “puts %Q<Found a statement%Fig::Statement.statementstatement.position_string().>” and get nice looking output regardless of whether the position is actually known or not.



184
185
186
187
188
# File 'lib/fig/statement.rb', line 184

def position_string
  return Fig::Statement.position_description(
    @line, @column, @source_description
  )
end

#unparse_as_version(unparser) ⇒ Object

Raises:

  • (NotImplementedError)


159
160
161
# File 'lib/fig/statement.rb', line 159

def unparse_as_version(unparser)
  raise NotImplementedError
end

#urlsObject



167
168
169
# File 'lib/fig/statement.rb', line 167

def urls()
  return []
end

#walk_statements(&block) ⇒ Object

Block will receive a Statement.



155
156
157
# File 'lib/fig/statement.rb', line 155

def walk_statements(&block)
  return
end