Sha256: 496996d80ebd8d0176f817feb46adbdab75b40fe8c0f576452da9394e9f72511

Contents?: true

Size: 824 Bytes

Versions: 1

Compression:

Stored size: 824 Bytes

Contents

# encoding: utf-8

module Piglet
  module Relation
    class Order # :nodoc:
      include Relation
    
      def initialize(relation, interpreter, fields, options)
        options ||= {}
        @interpreter = interpreter
        @sources, @parallel = [relation], options[:parallel]
        @fields = fields.is_a?(Enumerable) ? fields : [fields]
      end
    
      def to_s
        target = @sources.first.respond_to?(:field_alias) ? @sources.first.field_alias : @sources.first.alias
        "ORDER #{target} BY #{field_strings}"
      end
    
    private
  
      def field_strings
        @fields.map { |f| field_string(f) }.join(', ')
      end
    
      def field_string(f)
        if f.is_a?(Enumerable)
          "#{f[0]} #{f[1].to_s.upcase}"
        else
          f.to_s
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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