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.



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

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



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

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



112
113
114
115
116
# File 'lib/fig/deparser.rb', line 112

def archive(statement)
  asset 'archive', statement

  return
end

#command(statement) ⇒ Object



118
119
120
# File 'lib/fig/deparser.rb', line 118

def command(statement)
  raise NotImplementedError.new self
end

#configuration(configuration_statement) ⇒ Object



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

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



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

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



211
212
213
# File 'lib/fig/deparser.rb', line 211

def grammar_description
  raise NotImplementedError.new self
end

#grammar_version(statement) ⇒ Object



149
150
151
# File 'lib/fig/deparser.rb', line 149

def grammar_version(statement)
  raise NotImplementedError.new self
end

#include(statement) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/fig/deparser.rb', line 153

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



165
166
167
# File 'lib/fig/deparser.rb', line 165

def include_file(statement)
  raise NotImplementedError.new self
end

#override(statement) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/fig/deparser.rb', line 169

def override(statement)
  add_indent

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

  return
end

#path(statement) ⇒ Object



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

def path(statement)
  # I'd really like to change this to "add", but because the command-line
  # option is "--append", I'm not going to.
  environment_variable(statement, 'append')

  return
end

#resource(statement) ⇒ Object



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

def resource(statement)
  asset 'resource', statement

  return
end

#retrieve(statement) ⇒ Object



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

def retrieve(statement)
  raise NotImplementedError.new self
end

#set(statement) ⇒ Object



199
200
201
202
203
# File 'lib/fig/deparser.rb', line 199

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

  return
end

#synthetic_raw_text(statement) ⇒ Object



205
206
207
208
209
# File 'lib/fig/deparser.rb', line 205

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

  return
end