Sha256: 3d9c2c6ab93de346d250626f9efcac0ea4a6d6814c193d641cd7fc18abf420c3

Contents?: true

Size: 967 Bytes

Versions: 2

Compression:

Stored size: 967 Bytes

Contents

require "find_with_order/version"
require "find_with_order/mysql_support"
require "find_with_order/pg_support"
require 'active_record'

module FindWithOrder
  class << self
    def supporter
      return FindWithOrder::PGSupport if defined?(PG)
      return FindWithOrder::MysqlSupport
    end
  end
end

class << ActiveRecord::Base
  def find_with_order(ids)
    return none if ids.blank?
    return FindWithOrder.supporter.find_with_order(self, ids.uniq)
  end

  def where_with_order(column, ids)
    return none if ids.blank?
    return FindWithOrder.supporter.where_with_order(self, column, ids.uniq)
  end

  def with_order(column, ids, null_first: false)
    FindWithOrder.supporter.with_order(self, column, ids, null_first: null_first)
  end
end

unless ActiveRecord::Base.respond_to?(:none) # extend only if not implement yet
  class ActiveRecord::Base
    def self.none #For Rails 3
      where('1=0')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
find_with_order-1.3.1 lib/find_with_order.rb
find_with_order-1.3.0 lib/find_with_order.rb