<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -335,11 +335,27 @@ All methods support this extra option.
 
 ## Scoping the find
 
-All the `by_*` methods takes a block which will then scope the find based on the options passed into it. The supported options are the same options that are supported by `ActiveRecord::Base.find`:
+All the `by_*` methods take a block which will then scope the find based on the options passed into it. You can also specify these options for each method, but the syntax may differ. The supported options are the same options that are supported by `find` from ActiveRecord. Please note that if you want to use conditions you *have* to use this syntax:
+
+     Post.by_month(1) { { :include =&gt; &quot;tags&quot;, :conditions =&gt; [&quot;tags.name = ?&quot;, 'ruby'] } }
+
+or the lengthened:
 
      Post.by_month(1) do
        { :include =&gt; &quot;tags&quot;, :conditions =&gt; [&quot;tags.name = ?&quot;, 'ruby'] }
      end
+    
+An alternative syntax to this is:
+
+     Post.by_month(1, { :include =&gt; &quot;tags&quot;, :conditions =&gt; [&quot;tags.name = ?&quot;, 'ruby'] })
+     
+## Ordering records
+
+To order the returned set of records you may specify an `:order` option which works the same was as a standard AR `:order` option:
+
+     Item.by_month(1, :order =&gt; &quot;position DESC&quot;)
+
+     
 ## &quot;Chronicable string&quot;
 
 This means a string that can be parsed with the Chronic gem.</diff>
      <filename>README.markdown</filename>
    </modified>
    <modified>
      <diff>@@ -5,11 +5,11 @@
 
 Gem::Specification.new do |s|
   s.name = %q{by_star}
-  s.version = &quot;0.3.0&quot;
+  s.version = &quot;0.3.1&quot;
 
   s.required_rubygems_version = Gem::Requirement.new(&quot;&gt;= 0&quot;) if s.respond_to? :required_rubygems_version=
   s.authors = [&quot;Ryan Bigg&quot;, &quot;Mislav Marohni\304\207&quot;]
-  s.date = %q{2009-10-17}
+  s.date = %q{2009-10-28}
   s.description = %q{ActiveRecord extension for easier date scopes and time ranges}
   s.email = %q{radarlistener@gmail.com}
   s.extra_rdoc_files = [
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
      &quot;Rakefile&quot;,
      &quot;VERSION&quot;,
      &quot;by_star.gemspec&quot;,
-     &quot;by_star.sqlite3&quot;,
      &quot;lib/by_star.rb&quot;,
      &quot;lib/calculations.rb&quot;,
      &quot;lib/calculations/count.rb&quot;,</diff>
      <filename>by_star.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -4,8 +4,8 @@ module ByStar
     include Sum
     
     private
-      def work_out_month(time, options = {})
-        year = options[:year] ||= Time.zone.now.year
+      def work_out_month(time, year=Time.zone.now.year)
+        year ||= Time.zone.now.year
         # Work out what actual month is.
         month = if time.is_a?(Numeric) &amp;&amp; (1..12).include?(time)
           time</diff>
      <filename>lib/calculations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,15 +1,20 @@
 module ByStar
   module Calculations
     module Count
-      def count_by_year(field=nil, year=Time.now.year, options={})
-        count(field, :conditions =&gt; conditions_for_range(start_of_year(year), end_of_year(year), options))
+      def count_by_year(field=nil, year=Time.now.year, options={}, &amp;block)
+        db_field = options.delete(:field)
+        scoped_by(block) do
+          count(field, { :conditions =&gt; conditions_for_range(start_of_year(year), end_of_year(year), db_field) }.reverse_merge!(options))
+        end
       end
       
-      def count_by_month(field=nil, month=Time.now.month, options={})
-        year, month = work_out_month(month, options)
-        count(field, :conditions =&gt; conditions_for_range(start_of_month(month, year), end_of_month(month, year), options))
+      def count_by_month(field=nil, month=Time.now.month, options={}, &amp;block)
+        db_field = options.delete(:field)
+        year, month = work_out_month(month, options.delete(:year))
+        scoped_by(block) do
+          count(field, { :conditions =&gt; conditions_for_range(start_of_month(month, year), end_of_month(month, year), db_field) }.reverse_merge!(options))
+        end
       end
     end
-    
   end
 end
\ No newline at end of file</diff>
      <filename>lib/calculations/count.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,17 @@
 module ByStar
   module Calculations
     module Sum
-      def sum_by_year(field, year=Time.zone.now.year, options={})
-        sum(field, :conditions =&gt; conditions_for_range(start_of_year(year), end_of_year(year), options))
+      def sum_by_year(field, year=Time.zone.now.year, options={}, &amp;block)
+        scoped_by(block) do
+          sum(field, { :conditions =&gt; conditions_for_range(start_of_year(year), end_of_year(year), options.delete(:field)) }.reverse_merge!(options))
+        end
       end
 
-      def sum_by_month(field, month=Time.zone.now.month, options={})
-        year, month = work_out_month(month, options)
-        sum(field, :conditions =&gt; conditions_for_range(start_of_month(month, year), end_of_month(month, year), options))
+      def sum_by_month(field, month=Time.zone.now.month, options={}, &amp;block)
+        year, month = work_out_month(month, options.delete(:year))
+        scoped_by(block) do
+          sum(field, { :conditions =&gt; conditions_for_range(start_of_month(month, year), end_of_month(month, year), options.delete(:field)) }.reverse_merge!(options))
+        end
       end
     end
   end</diff>
      <filename>lib/calculations/sum.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,15 +3,15 @@ module ByStar
 
     private
     
-    def start_of_year(year=Time.now.year)
+    def start_of_year(year=Time.zone.now.year)
       Time.utc(year, 1, 1)
     end
     
-    def end_of_year(year=Time.now.year)
+    def end_of_year(year=Time.zone.now.year)
       start_of_year.end_of_year
     end
     
-    def start_of_month(month, year=Time.now.year)
+    def start_of_month(month, year=Timeow.year)
       Time.utc(year, month, 1)
     end
     </diff>
      <filename>lib/range_calculations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,17 @@
 module Shared
-  def conditions_for_range(start_time, end_time, options = {})
-    field = connection.quote_table_name(table_name) &lt;&lt; '.' &lt;&lt; connection.quote_column_name(options[:field] || &quot;created_at&quot;)
+  def conditions_for_range(start_time, end_time, field=&quot;created_at&quot;)
+    field = connection.quote_table_name(table_name) &lt;&lt; '.' &lt;&lt; connection.quote_column_name(field || &quot;created_at&quot;)
     [&quot;#{field} &gt;= ? AND #{field} &lt;= ?&quot;, start_time.utc, end_time.utc]
   end
+  
+  private 
+  def scoped_by(options=nil, &amp;block)
+    if options &amp;&amp; scope = options.call
+      with_scope(:find =&gt; scope) do
+        block.call
+      end
+    else
+      block.call
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/shared.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ module ByStar
     #   by_month(time)
     def by_month(time=Time.zone.now.month, options={}, &amp;block)
       time = Time.zone.now.month if time.nil?
-      year, month = work_out_month(time, options)
+      year, month = work_out_month(time, options.delete(:year))
   
       start_time = start_of_month(month, year)
       end_time = start_time.end_of_month
@@ -71,7 +71,7 @@ module ByStar
       time = parse(time)
   
       # If options[:year] is passed in, use that year regardless.
-      year = work_out_year(options[:year]) if options[:year]
+      year = work_out_year(options.delete(:year)) if options[:year]
       # If the first argument is a date or time, ask it for the year
       year ||= time.year unless time.is_a?(Numeric)
       # If the first argument is a fixnum, assume this year.
@@ -180,13 +180,11 @@ module ByStar
       
       def by_direction(condition, time, options = {}, &amp;block)
         field = connection.quote_table_name(table_name)
-        field &lt;&lt; &quot;.&quot; &lt;&lt; connection.quote_column_name(options[:field] || &quot;created_at&quot;)
-        with_scope(:find =&gt; { :conditions =&gt; [&quot;#{field} #{condition} ?&quot;, time.utc] }) do
-          if block_given?
-            with_scope(:find =&gt; block.call) do
-              find(:all)
-            end
-          else
+        field &lt;&lt; &quot;.&quot; &lt;&lt; connection.quote_column_name(options.delete(:field) || &quot;created_at&quot;)
+        validate_find_options(options)
+        scoping = { :conditions =&gt; [&quot;#{field} #{condition} ?&quot;, time.utc] }.merge(options)
+        with_scope(:find =&gt; scoping) do
+          scoped_by(block) do
             find(:all)
           end
         end
@@ -198,15 +196,11 @@ module ByStar
         end_time = parse(end_time)
     
         raise ParseError, &quot;End time is before start time, searching like this will return no results.&quot; if end_time &lt; start_time
-        order = options.delete(:order)
-        scoping = { :conditions =&gt; conditions_for_range(start_time, end_time, options) }
-        scoping.merge!(:order =&gt; order) if order
+        field = options.delete(:field)
+        validate_find_options(options)
+        scoping = { :conditions =&gt; conditions_for_range(start_time, end_time, field) }.merge(options)
         with_scope(:find =&gt; scoping) do
-          if block_given?
-            with_scope(:find =&gt; block.call) do
-              find(:all)
-            end
-          else
+          scoped_by(block) do
             find(:all)
           end
         end</diff>
      <filename>lib/vanilla.rb</filename>
    </modified>
    <modified>
      <diff>@@ -310,6 +310,11 @@ describe Post do
       it &quot;should be able to find all events before Ryan's birthday using a non-standard field&quot; do
         Event.past(&quot;04-12-#{Time.zone.now.year}&quot;.to_time, :field =&gt; &quot;start_time&quot;).size.should eql(7)
       end 
+      
+      it &quot;should be able to order the find&quot; do
+        find(Date.today, :order =&gt; &quot;created_at ASC&quot;).first.text.should eql(&quot;Last year&quot;)
+        find(Date.today, :order =&gt; &quot;created_at DESC&quot;).first.text.should eql(&quot;post 0&quot;)
+      end
     
     end
   
@@ -492,6 +497,15 @@ describe Post do
           { :include =&gt; :tags, :conditions =&gt; [&quot;tags.name = ?&quot;, 'tomorrow'] }
         end.size.should eql(1)
       end
+      
+      it &quot;should work when block is empty&quot; do
+        stub_time
+        Post.future { }.size.should eql(71)
+      end
+      
+      it &quot;should be able to find a single post from the future with the tag 'tomorrow' (redux)&quot; do
+        Post.future(Time.zone.now, :include =&gt; :tags, :conditions =&gt; [&quot;tags.name = ?&quot;, 'tomorrow']).size.should eql(1)
+      end
     
     end
   
@@ -525,6 +539,12 @@ describe Post do
           it &quot;different year&quot; do
             Invoice.count_by_year(:all, 2008)
           end
+          
+          it &quot;current year with the given tag&quot; do
+            Post.count_by_year do
+              { :include =&gt; :tags, :conditions =&gt; [&quot;tags.name = ?&quot;, 'tomorrow'] }
+            end.should eql(1)
+          end
         end
       
         describe &quot;by month&quot; do
@@ -538,7 +558,17 @@ describe Post do
         
           it &quot;different month&quot; do
             stub_time
-            Invoice.count_by_month(:all, 9).should eql(9)
+            Invoice.count_by_month(:all, 9)
+          end
+          
+          it &quot;current month with the given tag&quot; do
+            Post.count_by_month(:all, Time.zone.now) do
+              { :include =&gt; :tags, :conditions =&gt; [&quot;tags.name = ?&quot;, 'tomorrow'] }
+            end.should eql(1)
+          end
+          
+          it &quot;current month with blank block&quot; do
+             Post.count_by_month(:all, Time.zone.now) { }.should eql(16)
           end
         end
       end</diff>
      <filename>spec/by_star_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>449c449776b27f7371ab2e81250e25bd94ccee18</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Bigg</name>
    <email>radarlistener@gmail.com</email>
  </author>
  <url>http://github.com/radar/by_star/commit/a486171ea354f457f9f7cc10128125f1b0a83d5d</url>
  <id>a486171ea354f457f9f7cc10128125f1b0a83d5d</id>
  <committed-date>2009-10-29T20:34:39-07:00</committed-date>
  <authored-date>2009-10-29T20:34:39-07:00</authored-date>
  <message>Refactored all the calls to with_scope into a single scoped_by method, added ordering to by_direction methods and now all methods support find options for scoping.</message>
  <tree>0991c6b721676fffdcf8c6c6a1eb2a54f7f81d6b</tree>
  <committer>
    <name>Ryan Bigg</name>
    <email>radarlistener@gmail.com</email>
  </committer>
</commit>
