Module: ChronoModel::TimeMachine::TimeQuery

Included in:
HistoryMethods
Defined in:
lib/chrono_model/time_machine.rb

Instance Method Summary collapse

Instance Method Details

#time_query(match, time, options) ⇒ Object

TODO Documentation



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/chrono_model/time_machine.rb', line 347

def time_query(match, time, options)
  range = columns_hash.fetch(options[:on].to_s)

  query = case match
  when :at
    build_time_query_at(time, range)

  when :not
    "NOT (#{build_time_query_at(time, range)})"

  when :before
    op = options.fetch(:inclusive, true) ? '&&' : '@>'
    build_time_query(['NULL', time_for_time_query(time, range)], range, op)

  when :after
    op = options.fetch(:inclusive, true) ? '&&' : '@>'
    build_time_query([time_for_time_query(time, range), 'NULL'], range, op)

  else
    raise ArgumentError, "Invalid time_query: #{match}"
  end

  where(query)
end