Module: Fingerprints::Extensions::ClassMethods

Defined in:
lib/fingerprints.rb

Instance Method Summary collapse

Instance Method Details

#has_fingerprints(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fingerprints.rb', line 18

def has_fingerprints(options = {})
  options.reverse_merge!(OPTIONS)

  class_eval <<-"EOV"
    class << self
      def fingerprint
        Thread.current["fingerprint_for_#{self.class}"]
      end
      def fingerprint=(val)
        Thread.current["fingerprint_for_#{self.class}"] = val
      end
    end
  EOV
end

#leaves_fingerprints(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fingerprints.rb', line 33

def leaves_fingerprints(options = {})
  options.reverse_merge!(OPTIONS)

  include Fingerprints::Extensions::InstanceMethods

  belongs_to :creator, :class_name => options[:class_name], :foreign_key => 'created_by'
  belongs_to :updater, :class_name => options[:class_name], :foreign_key => 'updated_by'
  before_create :fingerprint_created_by
  before_update :fingerprint_updated_by
  define_method('fingerprint_created_by') {|*args| set_fingerprint_for(:created_by, options) }
  define_method('fingerprint_updated_by') {|*args| set_fingerprint_for(:updated_by, options) }
end