Module: PaperTrail::ActiveRecordExt::VersionConcernExt::ClassMethods

Defined in:
lib/paper_trail/active_record/version_extensions.rb

Instance Method Summary collapse

Instance Method Details

#between_inclusive(start_time, end_time) ⇒ Object

Same as between but uses gteq/lteq instead of gt/lt



27
28
29
30
31
32
# File 'lib/paper_trail/active_record/version_extensions.rb', line 27

def between_inclusive(start_time, end_time)
  where(
    arel_table[:created_at].gteq(start_time).
    and(arel_table[:created_at].lteq(end_time))
  ).order(timestamp_sort_order)
end

#preceding_inclusive(obj, timestamp_arg = false) ⇒ Object

Returns versions before obj. Same as preceding but uses lteq instead of lt

Parameters:

  • obj
    • a Version or a timestamp
  • timestamp_arg (defaults to: false)
    • boolean - When true, obj is a timestamp. Default: false.

Returns:

  • ActiveRecord::Relation



16
17
18
19
20
21
22
23
24
# File 'lib/paper_trail/active_record/version_extensions.rb', line 16

def preceding_inclusive(obj, timestamp_arg = false)
  if timestamp_arg != true && primary_key_is_int?
    return where(arel_table[primary_key].lteq(obj.id)).order(arel_table[primary_key].desc)
  end

  obj = obj.send(:created_at) if obj.is_a?(self)
  where(arel_table[:created_at].lteq(obj)).
    order(timestamp_sort_order("desc"))
end