class ActionSet::SortInstructions
Public Class Methods
new(params, set, controller)
click to toggle source
# File lib/action_set/sort_instructions.rb, line 5 def initialize(params, set, controller) @params = params @set = set @controller = controller end
Public Instance Methods
get()
click to toggle source
# File lib/action_set/sort_instructions.rb, line 11 def get instructions_hash = if form_friendly_complex_params? form_friendly_complex_params_to_hash elsif form_friendly_simple_params? form_friendly_simple_params_to_hash else @params end instructions_hash.transform_values { |v| v.remove('ending') } end
Private Instance Methods
form_friendly_complex_params?()
click to toggle source
# File lib/action_set/sort_instructions.rb, line 25 def form_friendly_complex_params? @params.key?(:'0') end
form_friendly_complex_params_to_hash()
click to toggle source
# File lib/action_set/sort_instructions.rb, line 34 def form_friendly_complex_params_to_hash ordered_instructions = @params.sort_by(&:first) array_of_instructions = ordered_instructions.map { |_, h| [h[:attribute], h[:direction]] } Hash[array_of_instructions] end
form_friendly_simple_params?()
click to toggle source
# File lib/action_set/sort_instructions.rb, line 29 def form_friendly_simple_params? @params.key?(:attribute) && @params.key?(:direction) end
form_friendly_simple_params_to_hash()
click to toggle source
# File lib/action_set/sort_instructions.rb, line 40 def form_friendly_simple_params_to_hash { @params[:attribute] => @params[:direction] } end