Skip to content

Commit

Permalink
Docs: .subsequent and .preceding
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredbeck committed Nov 8, 2015
1 parent 43e1039 commit e177db2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/paper_trail/version_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ def not_creates
where 'event <> ?', 'create'
end

# Expects `obj` to be an instance of `PaperTrail::Version` by default,
# but can accept a timestamp if `timestamp_arg` receives `true`
# Returns versions after `obj`.
#
# @param obj - a `Version` or a timestamp
# @param timestamp_arg - boolean - When true, `obj` is a timestamp.
# Default: false.
# @return `ActiveRecord::Relation`
# @api public
def subsequent(obj, timestamp_arg = false)
if timestamp_arg != true && self.primary_key_is_int?
return where(arel_table[primary_key].gt(obj.id)).order(arel_table[primary_key].asc)
Expand All @@ -67,6 +72,13 @@ def subsequent(obj, timestamp_arg = false)
where(arel_table[PaperTrail.timestamp_field].gt(obj)).order(self.timestamp_sort_order)
end

# Returns versions before `obj`.
#
# @param obj - a `Version` or a timestamp
# @param timestamp_arg - boolean - When true, `obj` is a timestamp.
# Default: false.
# @return `ActiveRecord::Relation`
# @api public
def preceding(obj, timestamp_arg = false)
if timestamp_arg != true && self.primary_key_is_int?
return where(arel_table[primary_key].lt(obj.id)).order(arel_table[primary_key].desc)
Expand All @@ -76,7 +88,6 @@ def preceding(obj, timestamp_arg = false)
where(arel_table[PaperTrail.timestamp_field].lt(obj)).order(self.timestamp_sort_order('desc'))
end


def between(start_time, end_time)
where(
arel_table[PaperTrail.timestamp_field].gt(start_time).
Expand Down

0 comments on commit e177db2

Please sign in to comment.