Class: Ordy::Orm::ActiveRecord::Orderable::BySpecified

Inherits:
Object
  • Object
show all
Defined in:
lib/ordy/orm/active_record/orderable/by_specified.rb

Class Method Summary collapse

Class Method Details

.call(scope, args) ⇒ Object

Parameters:

  • scope (Model::ActiveRecord_Relation)
  • args (Hash)

    (:table, :column)



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ordy/orm/active_record/orderable/by_specified.rb', line 8

def self.call(scope, args)
  connection = scope.connection
  table = connection.quote_table_name(args[:table])
  column = connection.quote_column_name(args[:column])
  values = args[:values].map { |value| connection.quote(value) }

  sql = values.map { |value| "#{table}.#{column}=#{value} DESC" }.join(',')

  connection.quote(sql)
  scope.order(Arel.sql(sql))
end