Module: SortableTable::App::Controllers::ApplicationController::ClassMethods

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) sortable_table_direction

Returns the value of attribute sortable_table_direction



38
39
40
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 38

def sortable_table_direction
  @sortable_table_direction
end

Instance Method Details

- (Object) define_sort_order(acceptable_columns, mappings)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 33

def define_sort_order(acceptable_columns, mappings)
  define_method(:default_sort_column) do
    acceptable_columns.first
  end

  attr_accessor :sortable_table_direction

  define_method(:sort_order) do |*default| 
    default = default.first
    direction = default_sort_direction(params[:order], default)
    column    = params[:sort] || default_sort_column
    self.sortable_table_direction = direction
    if params[:sort] && acceptable_columns.include?(column)
      column = mappings[column.to_sym] || column
      handle_compound_sorting(column, sql_sort_direction(direction))
    else
      "#{acceptable_columns.first} #{sql_sort_direction(direction)}"
    end
  end

  helper_method :sort_order, :default_sort_column, :sortable_table_direction
end

- (Object) join_array_and_hash_values(array, hash)



28
29
30
31
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 28

def join_array_and_hash_values(array, hash)
  array.collect { |each| each.to_s } + 
    hash.keys.collect { |each| each.to_s }
end

- (Object) pop_hash_from_list(args)



20
21
22
23
24
25
26
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 20

def pop_hash_from_list(args)
  if args.last.is_a?(Hash)
    args.pop
  else
    {}
  end
end

- (Object) sortable_attributes(*args)



14
15
16
17
18
# File 'lib/sortable_table/app/controllers/application_controller.rb', line 14

def sortable_attributes(*args)
  mappings           = pop_hash_from_list(args)
  acceptable_columns = join_array_and_hash_values(args, mappings)
  define_sort_order(acceptable_columns, mappings)
end