Module: ByStar::ActiveRecord::ClassMethods

Includes:
Base
Defined in:
lib/by_star/orm/active_record/by_star.rb

Instance Method Summary collapse

Methods included from Base

#by_star_end_field, #by_star_field, #by_star_offset, #by_star_scope, #by_star_start_field

Methods included from Directional

#after, #before

Methods included from Between

#between_times, #by_calendar_month, #by_day, #by_fortnight, #by_month, #by_quarter, #by_week, #by_weekend, #by_year, #next_day, #next_fortnight, #next_month, #next_week, #next_year, #past_day, #past_fortnight, #past_month, #past_week, #past_year, #today, #tomorrow, #yesterday

Instance Method Details

#between(*args) ⇒ Object



25
26
27
28
# File 'lib/by_star/orm/active_record/by_star.rb', line 25

def between(*args)
  ActiveSupport::Deprecation.warn 'ByStar `between` method will be removed in v3.0.0. Please use `between_times`'
  between_times(*args)
end

#between_times_query(start, finish, options = {}) ⇒ Object

Returns all records between a given start and finish time.

Currently only supports Time objects.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/by_star/orm/active_record/by_star.rb', line 11

def between_times_query(start, finish, options={})
  start_field = by_star_start_field(options)
  end_field = by_star_end_field(options)

  scope = by_star_scope(options)
  scope = if options[:strict] || start_field == end_field
    scope.where("#{start_field} >= ? AND #{end_field} <= ?", start, finish)
  else
    scope.where("#{end_field} > ? AND #{start_field} < ?", start, finish)
  end
  scope = scope.order(options[:order]) if options[:order]
  scope
end