Module ActiveRecord::Acts::Taggable::SingletonMethods
In: lib/taggable.rb

Methods

Public Instance methods

Takes the result of a tags_count call and an array of categories and distributes the entries in the tags_count hash evenly across the categories based on the count value for each tag.

Typically, this is used to display a ‘tag cloud’ in your UI.

The options are:

tag_hash => The tag hash returned from a tags_count call

category_list => An array containing the categories to split the tags into

block => { |tag, category| }

The block parameters are:

+:tag+ => The tag key from the tag_hash

+:category+ => The category value from the category_list that this tag is in

This method returns a simple count of the number of distinct objects Which match the tags provided

 by Lon Baker

Finds other records that share the most tags with the record passed as the related parameter. Useful for constructing ‘Related’ or ‘See Also’ boxes and lists.

The options are:

+:limit+: defaults to 5, which means the method will return the top 5 records that share the greatest number of tags with the passed one. +:conditions+: any additional conditions that should be appended to the WHERE clause of the finder SQL. Just like regular +ActiveRecord::Base#find+ methods.

Finds other tags that are related to the tags passed through the tags parameter, by finding common records that share similar sets of tags. Useful for constructing ‘Related tags’ lists.

The options are:

+:separator+ => defines the separator (String or Regex) used to split the tags parameter and defaults to ’ ’ (space and line breaks).

+:raw+: If you just want to get the raw output of the SQL statement (Array of Hashes), instead of the regular tags count Hash, set this to true.

+:limit+: the same as used in regular +ActiveRecord::Base#find+ methods.

This method searches for objects of the taggable class and subclasses that contains specific tags associated to them. The tags to be searched for can be passed to the +:any+ or +:all+ options, either as a String or an Array.

The options are:

+:any+: searches objects that are related to ANY of the given tags

+:all+: searcher objects that are related to ALL of the given tags

+:separator+: a string, regex or Proc object that will be used to split the tags string passed to +:any+ or +:all+ using a regular +String#split+ method. If a Proc is passed, the proc should split the string in any way it wants and return an array of strings.

+:conditions+: any additional conditions that should be appended to the WHERE clause of the finder SQL. Just like regular +ActiveRecord::Base#find+ methods.

+:order+: the same as used in regular +ActiveRecord::Base#find+ methods.

+:limit+: the same as used in regular +ActiveRecord::Base#find+ methods.

Looks for items with and old_tag and replaces it with all of new_tag

 The +old_tag+ ,+new_tag+ parameters can be a +String+, +Array+ or a +Proc+ object.
 If it's a +String+, it's split using the +:separator+ specified in
 the +options+ hash. If it's an +Array+ it is flattened and compacted.
 Duplicate entries will be removed as well. Tag names are also stripped
 of trailing and leading whitespace. If a Proc is passed,
 the proc should split the string in any way it wants and return an array of strings.

 The +options+ hash has the following parameters:

 +:separator+: a string, regex or Proc object that will be used to split the
 tags string passed to +:any+ or +:all+ using a regular +String#split+ method.
 If a Proc is passed, the proc should split the string in any way it wants
 and return an array of strings.

 +:conditions+: any additional conditions that should be appended to the
 WHERE clause of the finder SQL. Just like regular +ActiveRecord::Base#find+ methods.
tag_count(options = {})

Alias for tags_count

This method counts the number of times the tags have been applied to your objects and, by default, returns a hash in the form of { ‘tag_name’ => count, … }

The options are:

+:raw+: If you just want to get the raw output of the SQL statement (Array of Hashes), instead of the regular tags count Hash, set this to true.

+:conditions+: any additional conditions that should be appended to the WHERE clause of the SQL. Just like in regular +ActiveRecord::Base#find+ methods.

+:order+: The same as used in +ActiveRecord::Base#find+ methods. By default, this is ‘count DESC’. This should only be used if you want to modify the SQL - to have sorted result be returned use +:sort_list+:

+:sort_list+: This is a proc that is used to return a sorted list instead of a hash

+:count+: Adds a HAVING clause to the SQL statement, where you can set conditions for the ‘count’ column. For example: ’> 50‘

+:limit+: the same as used in regular +ActiveRecord::Base#find+ methods.

[Validate]