Module: Ddb::Userstamp::Stamper::InstanceMethods

Defined in:
lib/stamper.rb

Instance Method Summary collapse

Instance Method Details

#reset_stamperObject

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



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

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

#stamperObject

Retrieves the existing stamper for the current request.



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

def stamper
  Thread.current["#{self.to_s.downcase}_#{self.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.



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

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

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