Module: ActiveRecord::Userstamp::Stampable::ClassMethods
- Defined in:
- lib/active_record/userstamp/stampable.rb
Instance Method Summary collapse
- #inherited(klass) ⇒ Object
-
#stampable(options = {}) ⇒ Object
This method customizes how the gem functions.
-
#stamper_class ⇒ Object
:nodoc:.
-
#without_stamps ⇒ Object
Temporarily allows you to turn stamping off.
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( = {}) self.stamper_class_name = .delete(:stamper_class_name) if .key?(:stamper_class_name) add_userstamp_associations() end |
#stamper_class ⇒ Object
: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_stamps ⇒ Object
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 |