Acts as Toucher plugin

Plugin details

This plugin helps you record interactions between two related models.

Websitehttp://acts-as-toucher.rubyforge.org/ Repositorysvn://rubyforge.org/var/svn/acts-as-toucher Author Bosko Milekic Tags touch, monitor LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install svn://rubyforge.org/var/svn/acts-as-toucher

First, create and run a Rails migration resembling the following:

class ActsAsRecentlyTouchedStructure < ActiveRecord::Migration
  def self.up
    create_table :touch_records do |t|
      t.column :created_at, :datetime
      t.column :touched_id, :integer
      t.column :touched_type, :string
      t.column :toucher_id, :integer
      t.column :toucher_type, :string
    end
  end

  def self.down
    drop_table :touch_records
  end
end


Then, suppose we are talking about the above described User/File scenario.
In such a scenario, you can do something like this from within your User class:

class User < ActiveRecord::Base
  acts_as_toucher :on => :file
end


Then you can do this:

@user = User.find(1)
@file = File.find(1)
@file2 = File.find(2)
@user.touch_file(@file)
@user.touch_file(@file2)
@user.touch_file(@file)
@my_ten_recently_touched_files = @user.touched_files(10)


It's also possible to specify an array/list for the :on option to acts_as_toucher. For instance:

class User < ActiveRecord::Base
  acts_as_toucher :on => [ :file, :directory ]
end


And so on...

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago