Class: ActsAsExplorable::Element::Sort

Inherits:
Base
  • Object
show all
Defined in:
lib/acts_as_explorable/element/sort.rb

Overview

Generates an order query part to sort by the given columns

Instance Attribute Summary

Attributes included from ActsAsExplorable::Element

#full_query, #model, #parameters, #query_parts, #query_string, #query_type

Instance Method Summary collapse

Methods included from ActsAsExplorable::Element

build, #execute, #initialize

Instance Method Details

#after_initObject



6
7
8
# File 'lib/acts_as_explorable/element/sort.rb', line 6

def after_init
  @query_type = :reorder
end

#renderObject



10
11
12
13
14
15
16
17
18
# File 'lib/acts_as_explorable/element/sort.rb', line 10

def render
  @full_query = @parameters.map do |f|
    if f =~ /(-asc|-desc)/
      { f.split('-').first.to_sym => f.split('-').last.to_sym }
    else
      { f.to_sym => :desc }
    end
  end
end