Sha256: 58f217fcb3bd901a40cd1b5c9ff4188ed74c188e915bb429832f7aa777c518e0

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

module AQL
  class Node
    class Operation
      # For operation
      class For < self
        include Concord.new(:local, :source, :body)

      private

        # Emit node
        #
        # @param [Buffer] buffer
        #
        # @return [self]
        #
        # @api private
        #
        def emit(buffer)
          buffer.append('FOR ')
          emit_local(buffer)
          emit_source(buffer)
          emit_body(buffer)
        end

        # Emit body
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_body(buffer)
          body.visit(buffer)
        end

        # Emit local
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_local(buffer)
          local.visit(buffer)
          buffer.append(' IN ')
        end

        # Emit source
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_source(buffer)
          local = source
          if local.kind_of?(Name)
            local.visit(buffer)
          else
            emit_source_parentheses(buffer)
          end
          buffer.append(' ')
        end

        # Emit source in parentheses
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_source_parentheses(buffer)
          buffer.parentheses do
            source.visit(buffer)
          end
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aql-0.0.3 lib/aql/node/operation/for.rb
aql-0.0.2 lib/aql/node/operation/for.rb
aql-0.0.1 lib/aql/node/operation/for.rb