Sha256: 7e2ff18d29713963b8cdd49bf6c61387dccf367d89738f7bc651c0cc9c6591e3

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

require 'fig/package_descriptor'
require 'fig/unparser'

module Fig; end
module Fig::Unparser; end

# Handles serializing of statements in the v0 grammar.
class Fig::Unparser::V0
  include Fig::Unparser

  def initialize(
    emit_as_input_or_to_be_published_values,
    indent_string = ' ' * 2,
    initial_indent_level = 0
  )
    @emit_as_input_or_to_be_published_values =
      emit_as_input_or_to_be_published_values
    @indent_string        = indent_string
    @initial_indent_level = initial_indent_level

    return
  end

  def command(statement)
    add_indent

    @text << %q<command ">
    @text << statement.command
    @text << %Q<"\n>

    return
  end

  def grammar_version(statement)
    add_indent

    # Comment out so that older clients don't have issues.
    @text << "# grammar v0\n"

    return
  end

  def retrieve(statement)
    add_indent

    @text << 'retrieve '
    @text << statement.var
    @text << '->'
    @text << statement.path
    @text << "\n"

    return
  end

  private

  def asset(keyword, statement)
    path  = asset_path statement
    quote = path =~ /[*?\[\]{}]/ ? '' : %q<">

    add_indent
    @text << keyword
    @text << ' '
    @text << quote
    @text << path
    @text << quote
    @text << "\n"

    return
  end

  def environment_variable(statement, keyword)
    add_indent

    @text << keyword
    @text << ' '
    @text << statement.name
    @text << '='
    @text << statement.value
    @text << "\n"

    return
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fig-0.1.77 lib/fig/unparser/v0.rb
fig-0.1.76 lib/fig/unparser/v0.rb
fig-0.1.75 lib/fig/unparser/v0.rb