Class: SmqlToAR::ConditionTypes::Functions::Order

Inherits:
Function
  • Object
show all
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

#args, #func, #model

Instance Method Summary collapse

Methods inherited from Function

inspect, try_parse

Methods included from Assertion

#raise_if, #raise_unless

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