Module: Userstamp::Stamper::InstanceMethods

Defined in:
lib/userstamp/stamper.rb

Instance Method Summary collapse

Instance Method Details

#reset_stamperObject

Sets the stamper back to nil to prepare for the next request.


34
35
36
# File 'lib/userstamp/stamper.rb', line 34

def reset_stamper
  Thread.current["#{to_s.downcase}_#{object_id}_stamper"] = nil
end

#stamperObject

Retrieves the existing stamper for the current request.


29
30
31
# File 'lib/userstamp/stamper.rb', line 29

def stamper
  Thread.current["#{to_s.downcase}_#{object_id}_stamper"]
end

#stamper=(object) ⇒ Object

Used to set the stamper for a particular request. See the Userstamp module for more details on how to use this method.


18
19
20
21
22
23
24
25
26
# File 'lib/userstamp/stamper.rb', line 18

def stamper=(object)
  object_stamper = if object.is_a?(ActiveRecord::Base)
                     object.send(object.class.primary_key.to_s.to_sym)
                   else
                     object
                   end

  Thread.current["#{to_s.downcase}_#{object_id}_stamper"] = object_stamper
end