Module: OrderOrder::Extensions
- Defined in:
- lib/order_order/extensions.rb
Constant Summary collapse
- DEFAULT_ALPHABETICAL_COLUMN =
:name- DEFAULT_CHRONOLOGICAL_COLUMN =
:created_at
Instance Method Summary collapse
-
#alphabetical(column_or_options = DEFAULT_ALPHABETICAL_COLUMN, options = {}) ⇒ Object
Order records alphabetically.
-
#chronological(column = DEFAULT_CHRONOLOGICAL_COLUMN) ⇒ Object
Order records by date, with the newest records first.
-
#reverse_alphabetical(column_or_options = DEFAULT_ALPHABETICAL_COLUMN, options = {}) ⇒ Object
Order records alphabetically.
-
#reverse_chronological(column = DEFAULT_CHRONOLOGICAL_COLUMN) ⇒ Object
Order records by date, with the oldest records first.
-
#since(time) ⇒ ActiveRecord::Relation
Return all records created SINCE the provided date.
Instance Method Details
#alphabetical(column_or_options = DEFAULT_ALPHABETICAL_COLUMN, options = {}) ⇒ Object
Order records alphabetically.
34 35 36 37 |
# File 'lib/order_order/extensions.rb', line 34 def alphabetical(=DEFAULT_ALPHABETICAL_COLUMN, ={}) column = get_alphabetical_column(, ) order("#{column} ASC") end |
#chronological(column = DEFAULT_CHRONOLOGICAL_COLUMN) ⇒ Object
Order records by date, with the newest records first.
date. Defaults to ‘created_at`
15 16 17 |
# File 'lib/order_order/extensions.rb', line 15 def chronological(column=DEFAULT_CHRONOLOGICAL_COLUMN) order("#{column} ASC") end |
#reverse_alphabetical(column_or_options = DEFAULT_ALPHABETICAL_COLUMN, options = {}) ⇒ Object
Order records alphabetically.
46 47 48 49 |
# File 'lib/order_order/extensions.rb', line 46 def reverse_alphabetical(=DEFAULT_ALPHABETICAL_COLUMN, ={}) column = get_alphabetical_column(, ) order("#{column} DESC") end |
#reverse_chronological(column = DEFAULT_CHRONOLOGICAL_COLUMN) ⇒ Object
Order records by date, with the oldest records first.
date. Defaults to ‘created_at`
23 24 25 |
# File 'lib/order_order/extensions.rb', line 23 def reverse_chronological(column=DEFAULT_CHRONOLOGICAL_COLUMN) order("#{column} DESC") end |
#since(time) ⇒ ActiveRecord::Relation
Return all records created SINCE the provided date
60 61 62 |
# File 'lib/order_order/extensions.rb', line 60 def since(time) where("created_at > ?", time) end |