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


378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/chrono_model/time_machine.rb', line 378

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