Module: Croods::Resource::Sorting

Defined in:
lib/croods/resource/sorting.rb

Instance Method Summary collapse

Instance Method Details

#order_attributeObject



12
13
14
15
16
# File 'lib/croods/resource/sorting.rb', line 12

def order_attribute
  @order_attribute ||= Croods::Attribute.new(
    'order', :string, null: true
  )
end

#order_by_attributeObject



6
7
8
9
10
# File 'lib/croods/resource/sorting.rb', line 6

def order_by_attribute
  @order_by_attribute ||= Croods::Attribute.new(
    'order_by', :string, null: true
  )
end

#order_paramsObject



18
19
20
# File 'lib/croods/resource/sorting.rb', line 18

def order_params
  @order_params ||= [order_by_attribute, order_attribute]
end

#sort_by(sort = nil) ⇒ Object



27
28
29
30
31
# File 'lib/croods/resource/sorting.rb', line 27

def sort_by(sort = nil)
  return @sort_by ||= :created_at unless sort

  @sort_by ||= sort
end

#sort_by_method?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/croods/resource/sorting.rb', line 22

def sort_by_method?
  sort_by.is_a?(Symbol) && !sort_by.to_s.in?(attribute_names) &&
    model.respond_to?(sort_by)
end