Module: Fig::Deparser

Included in:
V0, V1, V2
Defined in:
lib/fig/deparser.rb,
lib/fig/deparser/v0.rb,
lib/fig/deparser/v1.rb,
lib/fig/deparser/v2.rb,
lib/fig/deparser/v1_base.rb

Defined Under Namespace

Modules: V1Base Classes: V0, V1, V2

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_for_statements(statements, emit_as_input_or_to_be_published_values) ⇒ Object

Determine the class of Deparser necessary for a set of Statements; the parameter can be a single statement or multiple. Returns both the class and a list of explanations of why the class was picked.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fig/deparser.rb', line 12

def self.class_for_statements(
  statements, emit_as_input_or_to_be_published_values
)
  statements = [statements].flatten

  versions =
    self.gather_versions statements, emit_as_input_or_to_be_published_values
  version = (versions.map {|version_info| version_info[0]}).max || 0
  explanations = (versions.collect {|v| v[1]}).reject {|e| e.nil?}

  case version
  when 0
    return Fig::Deparser::V0, explanations
  when 1
    return Fig::Deparser::V1, explanations
  when 2
    return Fig::Deparser::V2, explanations
  end

  raise "Unexpected version #{version}."
end

.determine_version_and_deparse(statements, emit_as_input_or_to_be_published_values) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/fig/deparser.rb', line 34

def self.determine_version_and_deparse(
  statements, emit_as_input_or_to_be_published_values
)
  deparser_class, explanations = self.class_for_statements(
    statements, emit_as_input_or_to_be_published_values
  )
  deparser = deparser_class.new emit_as_input_or_to_be_published_values

  return (deparser.deparse [statements].flatten), explanations
end

Instance Method Details

#archive(statement) ⇒ Object



114
115
116
117
118
# File 'lib/fig/deparser.rb', line 114

def archive(statement)
  asset 'archive', statement

  return
end

#command(statement) ⇒ Object

Raises:

  • (NotImplementedError)


120
121
122
123
124
# File 'lib/fig/deparser.rb', line 120

def command(statement)
  raise NotImplementedError.new(
    "#{__callee__}() not implemented on #{self.class}."
  )
end

#configuration(configuration_statement) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/fig/deparser.rb', line 126

def configuration(configuration_statement)
  if ! @text.empty?
    @text << "\n"
  end

  add_indent
  @text << 'config '
  @text << configuration_statement.name
  @text << "\n"

  @indent_level += 1
  begin
    configuration_statement.statements.each do
      |statement|

      statement.deparse_as_version(self)
    end
  ensure
    @indent_level -= 1
  end

  add_indent
  @text << "end\n"

  return
end

#deparse(statements) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fig/deparser.rb', line 99

def deparse(statements)
  # It's double dispatch time!

  @text         = ''
  @indent_level = @initial_indent_level

  statements.each { |statement| statement.deparse_as_version(self) }

  text          = @text
  @text         = nil
  @indent_level = nil

  return text
end

#grammar_descriptionObject

Raises:

  • (NotImplementedError)


219
220
221
222
223
# File 'lib/fig/deparser.rb', line 219

def grammar_description
  raise NotImplementedError.new(
    "#{__callee__}() not implemented on #{self.class}."
  )
end

#grammar_version(statement) ⇒ Object

Raises:

  • (NotImplementedError)


153
154
155
156
157
# File 'lib/fig/deparser.rb', line 153

def grammar_version(statement)
  raise NotImplementedError.new(
    "#{__callee__}() not implemented on #{self.class}."
  )
end

#include(statement) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/fig/deparser.rb', line 159

def include(statement)
  add_indent

  @text << 'include '
  @text << Fig::PackageDescriptor.format(
    statement.package_name, statement.version, statement.config_name
  )
  @text << "\n"

  return
end

#include_file(statement) ⇒ Object

Raises:

  • (NotImplementedError)


171
172
173
174
175
# File 'lib/fig/deparser.rb', line 171

def include_file(statement)
  raise NotImplementedError.new(
    "#{__callee__}() not implemented on #{self.class}."
  )
end

#override(statement) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/fig/deparser.rb', line 177

def override(statement)
  add_indent

  @text << 'override '
  @text << Fig::PackageDescriptor.format(
    statement.package_name, statement.version, nil
  )
  @text << "\n"

  return
end

#path(statement) ⇒ Object



189
190
191
192
193
# File 'lib/fig/deparser.rb', line 189

def path(statement)
  environment_variable(statement, 'add')

  return
end

#resource(statement) ⇒ Object



195
196
197
198
199
# File 'lib/fig/deparser.rb', line 195

def resource(statement)
  asset 'resource', statement

  return
end

#retrieve(statement) ⇒ Object

Raises:

  • (NotImplementedError)


201
202
203
204
205
# File 'lib/fig/deparser.rb', line 201

def retrieve(statement)
  raise NotImplementedError.new(
    "#{__callee__}() not implemented on #{self.class}."
  )
end

#set(statement) ⇒ Object



207
208
209
210
211
# File 'lib/fig/deparser.rb', line 207

def set(statement)
  environment_variable(statement, 'set')

  return
end

#synthetic_raw_text(statement) ⇒ Object



213
214
215
216
217
# File 'lib/fig/deparser.rb', line 213

def synthetic_raw_text(statement)
  @text << statement.text

  return
end