module Userstamper::Stamper::InstanceMethods
Public Instance Methods
reset_stamper()
click to toggle source
Sets the stamper back to nil
to prepare for the next request.
# File lib/userstamper/stamper.rb, line 31 def reset_stamper self.stamper = nil end
stamper()
click to toggle source
Retrieves the existing stamper.
# File lib/userstamper/stamper.rb, line 26 def stamper Thread.current[stamper_identifier] end
stamper=(object)
click to toggle source
Used to set the current stamper for this model.
@overload stamper=(object_id)
@param [Fixnum] object_id The ID of the stamper. @return [Fixnum]
@overload stamper=(object)
@param [ActiveRecord::Base] object The stamper object. @return [ActiveRecord::Base]
# File lib/userstamper/stamper.rb, line 21 def stamper=(object) Thread.current[stamper_identifier] = object end
with_stamper(stamper) { || ... }
click to toggle source
For the duration that execution is within the provided block, the stamper for this class would be the specified value.
This replaces the {#stamper=} and {#reset_stamper} pair because this guarantees exception safety.
# File lib/userstamper/stamper.rb, line 40 def with_stamper(stamper) old_stamper = self.stamper self.stamper = stamper yield ensure self.stamper = old_stamper end
Private Instance Methods
stamper_identifier()
click to toggle source
# File lib/userstamper/stamper.rb, line 50 def stamper_identifier "#{self.to_s.downcase}_#{self.object_id}_stamper" end