Module: Sequel::Plugins::Touch::InstanceMethods

Defined in:
lib/sequel/lib/sequel/plugins/touch.rb

Instance Method Summary collapse

Instance Method Details

#after_destroyObject

Touch all of the model's touched_associations when destroying the object.


70
71
72
73
# File 'lib/sequel/lib/sequel/plugins/touch.rb', line 70

def after_destroy
  super
  touch_associations
end

#after_updateObject

Touch all of the model's touched_associations when updating the object.


76
77
78
79
# File 'lib/sequel/lib/sequel/plugins/touch.rb', line 76

def after_update
  super
  touch_associations
end

#touch(column = nil) ⇒ Object

Touch the model object. If a column is not given, use the model's touch_column as the column. If the column to use is not one of the model's columns, just save the changes to the object instead of attempting to a value that doesn't exist.


85
86
87
88
89
90
91
92
93
# File 'lib/sequel/lib/sequel/plugins/touch.rb', line 85

def touch(column=nil)
  if column
    set(column=>touch_instance_value)
  else
    column = model.touch_column
    set(column=>touch_instance_value) if columns.include?(column)
  end
  save_changes
end