Skip to content

Commit

Permalink
isolate timeless table into a singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurnn committed Sep 23, 2013
1 parent e3beb25 commit f91feef
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/mongoid/timestamps/timeless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ def timeless?
self.class.timeless?
end

private

module ClassMethods
class << self

def timeless_table
Thread.current['[mongoid]:timeless'] ||= Hash.new
end
delegate :[]=, :[], to: :timeless_table
end

private

module ClassMethods

# Begin an execution that should skip timestamping.
#
Expand All @@ -57,20 +60,20 @@ def timeless
counter = 0
counter += 1 if self < Mongoid::Timestamps::Created
counter += 1 if self < Mongoid::Timestamps::Updated
self[name] = counter
Timeless[name] = counter
self
end

def clear_timeless_option
if counter = self[name]
if counter = Timeless[name]
counter -= 1
self[name] = (counter == 0) ? nil : counter
Timeless[name] = (counter == 0) ? nil : counter
end
true
end

def timeless?
!!self[name]
!!Timeless[name]
end
end
end
Expand Down

0 comments on commit f91feef

Please sign in to comment.