Permalink
Browse files

documents public API.

  • Loading branch information...
1 parent 79f9684 commit fec9ddab61e51c7c87f589f5f1d51ae54f8cb9ef David Werlen committed Feb 20, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 lib/asc_desc/model_additions.rb
@@ -1,12 +1,55 @@
module AscDesc
module ModelAdditions
+ # Call <tt>asc</tt> on an ActiveRecord object or on an ActiveRecord::Relation object to sort
+ # the column(s) in an ascending way.
+ #
+ # using a symbol for the name of the column
+ # Candy.where(:sugar => true).asc(:name)
+ #
+ # using a string for the name of the column
+ # Candy.where(:sugar => true).asc('name')
+ #
+ # using multiple parameters to specify more than one column for the sort clause
+ # Candy.where(:sugar => true).asc(:classification, :name)
+ #
+ # using an array to pass mutliple argument
+ # Candy.where(:sugar => true).asc([:classification, :name])
+ #
+ # using a string to specify more than one column for the sort clause
+ # Candy.where(:sugar => true).asc('classification, name')
+ #
+ # the method is chainable
+ # Candy.where(:sugar => true).asc(:classification).asc(:name)
+ #
def asc(*args)
self.order AscDesc.format_order_clause(*args << AscDesc::ASC)
end
alias :ascending :asc
alias :ascending_order :asc
+
+ # Call <tt>desc</tt> on an ActiveRecord object or on an ActiveRecord::Relation object to sort
+ # the column(s) in a descending way.
+ #
+ # using a symbol for the name of the column
+ # Candy.where(:sugar => true).desc(:name)
+ #
+ # using a string for the name of the column
+ # Candy.where(:sugar => true).desc('name')
+ #
+ # using multiple parameters to specify more than one column for the sort clause
+ # Candy.where(:sugar => true).desc(:classification, :name)
+ #
+ # using an array to pass mutliple argument
+ # Candy.where(:sugar => true).desc([:classification, :name])
+ #
+ # using a string to specify more than one column for the sort clause
+ # Candy.where(:sugar => true).desc('classification, name')
+ #
+ # the method is chainable
+ # Candy.where(:sugar => true).desc(:classification).desc(:name)
+ #
def desc(*args)
self.order AscDesc.format_order_clause(*args << AscDesc::DESC)
end

0 comments on commit fec9dda

Please sign in to comment.