Module: ActiveRecord::Userstamp::Stampable::ClassMethods

Defined in:
lib/active_record/userstamp/stampable.rb

Instance Method Summary collapse

Instance Method Details

#inherited(klass) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/active_record/userstamp/stampable.rb', line 22

def inherited(klass)
  super

  klass.class_eval do
    add_userstamp_associations({})
  end
end

#stampable(options = {}) ⇒ Object

This method customizes how the gem functions. For example:

class Post < ActiveRecord::Base
  stampable stamper_class_name: Person.name,
            with_deleted:       true
end

The method will set up all the associations. Extra arguments (like :with_deleted) will be propagated to the associations.

By default, the deleter association is not defined unless the :deleter_attribute is set in the gem configuration.



42
43
44
45
46
# File 'lib/active_record/userstamp/stampable.rb', line 42

def stampable(options = {})
  self.stamper_class_name = options.delete(:stamper_class_name) if options.key?(:stamper_class_name)

  add_userstamp_associations(options)
end

#stamper_classObject

:nodoc:



63
64
65
# File 'lib/active_record/userstamp/stampable.rb', line 63

def stamper_class #:nodoc:
  stamper_class_name.to_s.camelize.constantize rescue nil
end

#without_stampsObject

Temporarily allows you to turn stamping off. For example:

Post.without_stamps do
  post = Post.find(params[:id])
  post.update_attributes(params[:post])
  post.save
end


55
56
57
58
59
60
61
# File 'lib/active_record/userstamp/stampable.rb', line 55

def without_stamps
  original_value = self.record_userstamp
  self.record_userstamp = false
  yield
ensure
  self.record_userstamp = original_value
end