Module: StandardNamedScopes
- Included in:
- Batch, Request, Sample, SampleTube
- Defined in:
- app/models/standard_named_scopes.rb
Constant Summary collapse
- SORT_FIELDS =
%i[created updated].freeze
- SORT_ORDERS =
{ first: 'DESC', last: 'ASC' }.freeze
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/models/standard_named_scopes.rb', line 6 def self.included(base) base.instance_eval do # Date ordering is better specified as "order_most_recently_created_first" or # "order_most_recently_updated_last". These names seem more readable and understandable. SORT_FIELDS.each do |field| SORT_ORDERS.each do |position, order_by| scope :"order_most_recently_#{field}_#{position}", lambda { order("#{quoted_table_name}.#{field}_at #{order_by}") } end end end end |