Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Mongoid support with potentially more ORMs in the future

  • Loading branch information...
commit be02d4a8b1d7ff8fb65806fee3ba8ddbaebcf8e6 1 parent d80cb79
@tazsingh tazsingh authored
View
3  lib/event_calendar.rb
@@ -1,4 +1,3 @@
-require 'event_calendar/railtie' if defined?(::Rails::Railtie)
module EventCalendar
def self.included(base)
@@ -188,3 +187,5 @@ def adjust_all_day_dates
end
end
+
+require 'event_calendar/railtie' if defined?(::Rails::Railtie)
View
15 lib/event_calendar/orm/mongoid.rb
@@ -0,0 +1,15 @@
+module EventCalendar
+ module Mongoid
+ module ClassMethods
+ # Override ActiveRecord version
+ def events_for_date_range(start_d, end_d, find_options = {})
+ # Merging find_options until https://github.com/mongoid/mongoid/issues/829 is fixed
+ where(find_options.merge(self.end_at_field.to_sym.lt => end_d.to_time.utc,
+ self.start_at_field.to_sym.gt => start_d.to_time.utc)).asc(self.start_at_field)
+ end
+ end
+ end
+end
+
+Mongoid::Document::ClassMethods.send :include, EventCalendar::ClassMethods
+Mongoid::Document::ClassMethods.send :include, EventCalendar::Mongoid::ClassMethods
View
3  lib/event_calendar/railtie.rb
@@ -14,3 +14,6 @@ class Railtie < Rails::Engine
end
end
end
+
+# Support other ORMs
+require 'event_calendar/orm/mongoid' if defined? Mongoid
Please sign in to comment.
Something went wrong with that request. Please try again.