Sha256: 31074817af96bc95e36ee0cdc4664be3db9fac44eb5573bf71dbd4317034c9a6

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

module Fig; end
module Fig::Unparser; end

# Handles serializing of statements in the v1 grammar.
module Fig::Unparser::V1Base
  def command(statement)
    add_indent
    @text << %Q<command\n>

    add_indent(@indent_level + 1)
    statement.command.each do
      |argument|

      emit_tokenized_value argument
      @text << ' '
    end

    @text << %Q<\n>
    add_indent
    @text << %Q<end\n>

    return
  end

  def retrieve(statement)
    add_indent

    @text << 'retrieve '
    @text << statement.variable
    @text << '->'

    emit_tokenized_value statement.tokenized_path

    @text << "\n"

    return
  end

  private

  def asset(keyword, statement)
    quote = statement.glob_if_not_url? ? %q<"> : %q<'>
    path  =
      asset_path(statement).gsub('\\', ('\\' * 4)).gsub(quote, "\\\\#{quote}")

    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 << '='

    emit_tokenized_value statement.tokenized_value

    @text << "\n"

    return
  end

  def emit_tokenized_value(tokenized_value)
    if tokenized_value.can_be_single_quoted?
      @text << %q<'>
      @text << tokenized_value.to_single_quoted_string
      @text << %q<'>
    else
      @text << %q<">
      @text << tokenized_value.to_escaped_string
      @text << %q<">
    end

    return
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fig-1.4.0 lib/fig/unparser/v1_base.rb
fig-1.3.0 lib/fig/unparser/v1_base.rb
fig-1.2.0 lib/fig/unparser/v1_base.rb