Module: ActiveRecord::Userstamp::Stamper::InstanceMethods
- Defined in:
- lib/active_record/userstamp/stamper.rb
Instance Method Summary collapse
-
#reset_stamper ⇒ Object
Sets the stamper back to
nil
to prepare for the next request. -
#stamper ⇒ Object
Retrieves the existing stamper.
-
#stamper=(object) ⇒ Object
Used to set the current stamper for this model.
-
#with_stamper(stamper) ⇒ Object
For the duration that execution is within the provided block, the stamper for this class would be the specified value.
Instance Method Details
#reset_stamper ⇒ Object
Sets the stamper back to nil
to prepare for the next request.
31 32 33 |
# File 'lib/active_record/userstamp/stamper.rb', line 31 def reset_stamper self.stamper = nil end |
#stamper ⇒ Object
Retrieves the existing stamper.
26 27 28 |
# File 'lib/active_record/userstamp/stamper.rb', line 26 def stamper Thread.current[stamper_identifier] end |
#stamper=(object_id) ⇒ Fixnum #stamper=(object) ⇒ ActiveRecord::Base
Used to set the current stamper for this model.
21 22 23 |
# File 'lib/active_record/userstamp/stamper.rb', line 21 def stamper=(object) Thread.current[stamper_identifier] = object end |
#with_stamper(stamper) ⇒ Object
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.
40 41 42 43 44 45 46 |
# File 'lib/active_record/userstamp/stamper.rb', line 40 def with_stamper(stamper) old_stamper = self.stamper self.stamper = stamper yield ensure self.stamper = old_stamper end |