lib/by_star/base.rb in by_star-2.2.0.rc1 vs lib/by_star/base.rb in by_star-2.2.0

- old
+ new

@@ -3,14 +3,16 @@ module Base include ByStar::Between include ByStar::Directional - def by_star_field(start_field = nil, end_field = nil, options = {}) - @by_star_start_field ||= start_field - @by_star_end_field ||= end_field + def by_star_field(*args) + options = args.extract_options! + @by_star_start_field ||= args[0] + @by_star_end_field ||= args[1] @by_star_offset ||= options[:offset] + @by_star_scope ||= options[:scope] end def by_star_offset(options = {}) (options[:offset] || @by_star_offset || 0).seconds end @@ -27,9 +29,22 @@ field = options[:field] || options[:end_field] || @by_star_end_field || by_star_start_field field.to_s + end + + def by_star_scope(options={}) + scope = options[:scope] || @by_star_scope || self + if scope.is_a?(Proc) + if scope.arity == 0 + return instance_exec(&scope) + else + return instance_exec(self, &scope) + end + else + return scope + end end protected # Wrapper function which extracts time and options for each by_star query.