Sha256: ce6583b60b7582009eeff9327681cff1740d8771a13f7f8d2ea33c5d71eed44d

Contents?: true

Size: 969 Bytes

Versions: 1

Compression:

Stored size: 969 Bytes

Contents

module Piglet
  module Relation
    class Stream # :nodoc:
      include Relation
      
      def initialize(source, args, options=nil)
        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.2.4 lib/piglet/relation/stream.rb