Module: Railsful::Interceptors::Sorting

Included in:
Serializer
Defined in:
lib/railsful/interceptors/sorting.rb

Overview

Interceptor that sorts a given ActiveRecord::Relation

Instance Method Summary collapse

Instance Method Details

#render(options) ⇒ Object



7
8
9
# File 'lib/railsful/interceptors/sorting.rb', line 7

def render(options)
  super(sorting_options(options))
end

#sorting_options(options) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/railsful/interceptors/sorting.rb', line 11

def sorting_options(options)
  # Check if json value should be sorted.
  return options unless sort?(options)

  # Get the relation from options hash so we can sort it
  relation = options.fetch(:json)

  options.merge(json: sort(relation))
end