Module | Sequel::Plugins::Touch
In: | lib/sequel/plugins/touch.rb

The touch plugin adds a touch method to model instances, which saves the object with a modified timestamp. By default, it uses the :updated_at column, but you can set which column to use. It also supports touching of associations, so that when the current model object is updated or destroyed, the associated rows in the database can have their modified timestamp updated to the current timestamp.

Since the instance touch method works on model instances, it uses Time.now for the timestamp. The association touching works on datasets, so it updates all related rows in a single query, using the SQL standard CURRENT_TIMESTAMP. Both of these can be overridden easily if necessary.

Usage:

      # Allow touching of all model instances (called before loading subclasses)
      Sequel::Model.plugin :touch

      # Allow touching of Album instances, with a custom column
      Album.plugin :touch, :column=>:updated_on

      # Allow touching of Artist instances, updating the albums and tags
      # associations when touching, touching the +updated_on+ column for
      # albums and the +updated_at+ column for tags
      Artist.plugin :touch, :associations=>[{:albums=>:updated_on}, :tags]

### Methods

configure

### Classes and Modules

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

### Constants

TOUCH_COLUMN_DEFAULT | = | :updated_at |  | The default column to update when touching

### Public Class methods

configure(model, opts={})

Set the touch_column and touched_associations variables for the model. Options:

- :associations - The associations to touch when a model instance is updated or destroyed. Can be a symbol for a single association, a hash with association keys and column values, or an array of symbols and/or hashes. If a symbol is used, the column used when updating the associated objects is the model‘s touch_column. If a hash is used, the value is used as the column to update.
- :column - The column to modify when touching a model instance.

[Source]

        # File lib/sequel/plugins/touch.rb, line 42
    42:       def self.configure(model, opts={})
    43:         model.touch_column = opts[:column] || TOUCH_COLUMN_DEFAULT if opts[:column] || !model.touch_column
    44:         model.instance_variable_set(:@touched_associations, {})
    45:         model.touch_associations(opts[:associations]) if opts[:associations]
    46:       end

[Validate]