lib/by_star.rb in by_star-2.0.0.beta1 vs lib/by_star.rb in by_star-2.1.0.beta2
- old
+ new
@@ -8,25 +8,27 @@
require 'by_star/by_month'
require 'by_star/by_fortnight'
require 'by_star/by_week'
require 'by_star/by_weekend'
require 'by_star/by_day'
+require 'by_star/by_quarter'
module ByStar
def by_star_field(field=nil)
@by_star_field ||= field
- @by_star_field || "created_at"
+ @by_star_field || "#{self.table_name}.created_at"
end
include ByDirection
include ByYear
include ByMonth
include ByFortnight
include ByWeek
include ByWeekend
include ByDay
+ include ByQuarter
class ParseError < StandardError
end
@@ -38,10 +40,11 @@
scope = where("#{field} >= ? AND #{field} <= ?",
start, finish)
scope = scope.order(options[:order]) if options[:order]
scope
end
+ alias_method :between_times, :between
private
# Used inside the by_* methods to determine what kind of object "time" is.
# These methods take the result of the time_klass method, and call other methods
@@ -55,9 +58,14 @@
end
end
end
-ActiveRecord::Base.send :extend, ByStar
-ActiveRecord::Relation.send :extend, ByStar
+if defined?(ActiveRecord)
+ ActiveRecord::Base.send :extend, ByStar
+ ActiveRecord::Relation.send :extend, ByStar
+ ActiveRecord::Base.send :include, ByStar::InstanceMethods
+end
-ActiveRecord::Base.send :include, ByStar::InstanceMethods
+if defined?(Mongoid)
+ require 'mongoid/by_star'
+end
\ No newline at end of file