lib/season.rb in season-0.1 vs lib/season.rb in season-0.2
- old
+ new
@@ -1,3 +1,32 @@
require "season/version"
require "season/configuration"
-require "season/active_record/scopes" if defined? ActiveRecord
+require "season/legacy"
+require "season/scope_builder"
+require "season/query_builder"
+
+module Season
+
+ QUERY_VERBS = ['before', 'after', 'between']
+
+ def self.included(base)
+ base.extend(ClassMethods)
+
+ mb = ScopeBuilder.new(base)
+
+ base.class_eval do
+ # DEFINE SCOPES DINAMICALLY
+ base.datetime_column_names.each do |column_name|
+ QUERY_VERBS.each do |query_verb|
+ mb.build(table_name, column_name, query_verb)
+ end
+ end
+ end
+ end
+
+ module ClassMethods
+ def datetime_column_names
+ columns.map { |c| c.name if c.type == :datetime }.compact
+ end
+ end
+end
+