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

Instance Method Details

#alphabetical(column_or_options = DEFAULT_ALPHABETICAL_COLUMN, options = {}) ⇒ Object

Order records alphabetically.

Parameters:

  • column_or_options (String) (defaults to: DEFAULT_ALPHABETICAL_COLUMN)

    the name of the column which represents the object’s name, or a hash of options. Defaults to ‘“name”`.

  • case_sensitive (Hash)

    a customizable set of options



34
35
36
37
# File 'lib/order_order/extensions.rb', line 34

def alphabetical(column_or_options=DEFAULT_ALPHABETICAL_COLUMN, options={})
  column = get_alphabetical_column(column_or_options, options)
  order("#{column} ASC")
end

#chronological(column = DEFAULT_CHRONOLOGICAL_COLUMN) ⇒ Object

Order records by date, with the newest records first.

date. Defaults to ‘created_at`

Parameters:

  • column (String) (defaults to: DEFAULT_CHRONOLOGICAL_COLUMN)

    the name of the column which represents the object’s



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.

Parameters:

  • column_or_options (String) (defaults to: DEFAULT_ALPHABETICAL_COLUMN)

    the name of the column which represents the object’s name, or a hash of options. Defaults to ‘“name”`.

  • case_sensitive (Hash)

    a customizable set of options



46
47
48
49
# File 'lib/order_order/extensions.rb', line 46

def reverse_alphabetical(column_or_options=DEFAULT_ALPHABETICAL_COLUMN, options={})
  column = get_alphabetical_column(column_or_options, options)
  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`

Parameters:

  • column (String) (defaults to: DEFAULT_CHRONOLOGICAL_COLUMN)

    the name of the column which represents the object’s



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

Parameters:

  • (Time)

Returns:

  • (ActiveRecord::Relation)


60
61
62
# File 'lib/order_order/extensions.rb', line 60

def since(time)
  where("created_at > ?", time)
end