Sha256: d4629f2f71c81bd5e5200627cd94c90189c97b1d29f3feab5aa3cc4241490bc4

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

module Piglet
  module Relation
    class Stream # :nodoc:
      include Relation
      
      def initialize(source, interpreter, args, options=nil)
        @interpreter = interpreter
        options ||= {}
        @sources = [source]
        args.each do |arg|
          @sources << arg if arg.is_a?(Relation) || arg.is_a?(Array)
        end
        @command_reference = (args - @sources).first
        @sources = @sources.flatten
        @command = options[:command]
        @schema = options[:schema]
      end
      
      def schema
        if @schema
          Piglet::Schema::Tuple.parse(@schema)
        else
          nil
        end
      end
      
      def to_s
        source_str = @sources.map { |s| s.alias }.join(', ')
        str = "STREAM #{source_str} THROUGH"
        if @command_reference
          str << " #{@command_reference}" 
        else
          str << " `#{@command}`"
        end
        if @schema
          str << " AS #{schema}"
        end
        str
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
piglet-0.3.0 lib/piglet/relation/stream.rb