Module: SortableTable::App::Controllers::ApplicationController::InstanceMethods

Defined in:
lib/sortable_table/app/controllers/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#default_sort_direction(order, default) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 58

def default_sort_direction(order, default)
  case
  when ! order.blank?                           then normalize_direction(order)
  when default.is_a?(Hash) && default[:default] then normalize_direction(default[:default])
  else "descending"
  end
end

#handle_compound_sorting(column, direction) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 81

def handle_compound_sorting(column, direction)
  if column.is_a?(Array)
    column.collect { |each| "#{each} #{direction}" }.join(',')
  else
    "#{column} #{direction}"
  end
end

#normalize_direction(direction) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 73

def normalize_direction(direction)
  case direction
  when "ascending", "asc" then "ascending"
  when "descending", "desc" then "descending"
  else raise RuntimeError.new("Direction must be ascending, asc, descending, or desc")
  end
end

#sql_sort_direction(direction) ⇒ Object



66
67
68
69
70
71
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 66

def sql_sort_direction(direction)
  case direction
  when "ascending",  "asc" then "asc"
  when "descending", "desc" then "desc"
  end
end