Sha256: 15658e46f604eaab834eb87d718e2ce75bd2a8f5313e91143e9fa33d793ed513

Contents?: true

Size: 563 Bytes

Versions: 4

Compression:

Stored size: 563 Bytes

Contents

module EasyOrderable
  class OrderArgumentsTransformer
    def initialize(args)
      @args = args
    end

    def call
      args.map do |association, direction|
        if association.include?('.')
          table_name, column_name = association.split('.')
          "#{quote(table_name.pluralize)}.#{quote(column_name)} #{direction}"
        else
          "#{quote(association)} #{direction}"
        end
      end
    end

    private

    attr_reader :args

    def quote(name)
      ActiveRecord::Base.connection.quote_column_name(name)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
easy_orderable-1.2.0 lib/easy_orderable/order_arguments_transformer.rb
easy_orderable-1.1.1 lib/easy_orderable/order_arguments_transformer.rb
easy_orderable-1.0.0 lib/easy_orderable/order_arguments_transformer.rb
easy_orderable-0.2.2 lib/easy_orderable/order_arguments_transformer.rb