Class: SmqlToAR::ConditionTypes::Functions::Order
- Defined in:
- lib/smql_to_ar/condition_types.rb
Constant Summary collapse
- Name =
:order
- Expected =
[String, Array, Hash, nil]
Instance Attribute Summary
Attributes inherited from Function
Instance Method Summary collapse
-
#initialize(model, func, args) ⇒ Order
constructor
A new instance of Order.
- #order_build(builder, table) ⇒ Object (also: #build)
Methods inherited from Function
Methods included from Assertion
Constructor Details
#initialize(model, func, args) ⇒ Order
Returns a new instance of Order.
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/smql_to_ar/condition_types.rb', line 427 def initialize model, func, args args = case args when String then [args] when Array, Hash then args.to_a when nil then nil else raise 'Oops' end args.andand.collect! do |o| o = Array.wrap o col = Column.new model, o.first o = 'desc' == o.last.to_s.downcase ? :DESC : :ASC raise_unless col.exist_in?, NonExistingColumnError.new( [:Column], col) [col, o] end super model, func, args end |
Instance Method Details
#order_build(builder, table) ⇒ Object Also known as: build
444 445 446 447 448 449 450 451 452 453 |
# File 'lib/smql_to_ar/condition_types.rb', line 444 def order_build builder, table return if @args.blank? @args.each do |o| col, o = o col.joins builder, table t = table + col.path #raise_unless 1 == t.length, RootOnlyFunctionError.new( t) builder.order t, col.col, o end end |