dm-tags

Get Version

0.0.3

Description

This package brings tagging to DataMapper. It is inspired by Acts As Taggable On by Michael Bleigh, github’s mbleigh. Props to him for the contextual tagging based on Acts As Taggable on Steroids.

Installing

sudo gem install dm-tags

Demonstration of usage

  require 'rubygems'
  require 'dm-core'
  require 'dm-tags'

  DataMapper.setup(:default, "sqlite3::memory:")

  class MyModel
    include DataMapper::Resource
    property :id, Integer, :serial => true
    has_tags_on :tags, :skills
  end

  DataMapper.auto_migrate!

  # Contextual tagging
  MyModel.taggable? #=> true
  MyModel.new.taggable? #=> true

  model = MyModel.new
  model.tag_list = 'test, me out,   please   '
  model.tag_list
  #=> ['me out', 'please', 'test'] # Sanitized and alphabetized
  model.save #=> true
  model.tags
  #=> [#<Tag id=1 name="me out">, #<Tag id=2 name="please">, #<Tag id=3 name="test">]
  model.tag_list = 'test, again'
  model.save #=> true
  model.tags
  #=> [#<Tag id=3 name="test">, #<Tag id=4 name="again">] # Checks for existing tags
  Tag.all
  #=> [#<Tag id=1 name="me out">, #<Tag id=2 name="please">,
  #    #<Tag id=3 name="test">, #<Tag id=4 name="again">]
  another = MyModel.new
  another.skill_list = 'test, all, you, like'
  another.save #=> true
  another.tag_list #=> []
  another.skills
  #=> [#<Tag id=5 name="all">, #<Tag id=6 name="like">,
  #    #<Tag id=3 name="test">, #<Tag id=7 name="you">]

  MyModel.tagged_with('test') #=> [#<MyModel id=1>, #<MyModel id=2>]
  MyModel.tagged_with('test', :on => 'tags') #=> [#<MyModel id=1>]
  MyModel.tagged_with('test', :on => 'skills') #=> [#<MyModel id=2>]

  # Traditional 'tags only' tagging

  class TagsOnly
    include DataMapper::Resource
    property :id, Integer, :serial => true
    has_tags
  end

  TagsOnly.auto_migrate!

  TagsOnly.taggable? #=> true
  TagsOnly.new.taggable? #=> true

  tags_only = TagsOnly.new
  tags_only.tag_list = 'tags, only'
  tags_only.tag_list #=> ['only', 'tags']
  tags_only.save #=> true
  tags_only.tags
  #=> [#<Tag id=8 name="only">, #<Tag id=9 name="tags">]  

Forum

http://groups.google.com/group/dm-tags

How to submit patches

Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.

You can fetch the source from either:

git clone git://rubyforge.org/dm-tags.git
git clone git://github.com/bobby/dm-tags.git

Build and test instructions

  cd dm-tags
  rake test
  rake install_gem

License

This code is free to use under the terms of the MIT license.

Contact

Comments are welcome. Send an email to Bobby Calderwood email via the forum.

Bobby Calderwood, 2nd August 2008
Theme extended from Paul Battley