0.0
No commit activity in last 3 years
No release in over 3 years
Mongoid tagging gem that holds meta about tags in a scoped context.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.5.2
>= 0
~> 1.2.8
~> 2.1.0
~> 2.3.0
~> 0.6.0

Runtime

 Project Readme

Mongoid Tag¶ ↑

This gem is heaviliy influenced by Aaron Qians mongoid_taggable_with_context gem. I needed a way to tag a model and let a contextual scope of that model hold meta-data about the tags.

In example: when I tag a product with “nice”, I wanted the products category to know how many products was tagged with “nice”. I also wanted to store additional data about this tag such as color (i.e colored labels on gmail.)

NOTE¶ ↑

This is my first gem ever, and it is experimental at the moment. Use it at your own risk…

Usage¶ ↑

class Product
  include Mongoid::Document
  include Mongoid::Tag
  belongs_to :category
  tag :tags, :meta_in => :category
end

class Category
  include Mongoid::Document
  include Mongoid::Tag::Meta
  tag_meta_for :tags
end

@c = Category.create
@product = Product.create(:tags => "new, expensive", :category => @c)

@product.tags => ["new", "expensive"]

@category.tags_with_weight => [["new", 1], ["expensive", 1]]

@category.add_tag("on sale", {:color => "#a2a2a2"}) #add any meta you want

@category.tags_with_meta => [["new", {:count => 1}], ["expensive", {:count => 1}], ["on sale", {:count => 0, :color => "#a2a2a2"}]]

Scopes¶ ↑

@category.products.with_all_tags(['tag1', 'tag2']) => products tagged with both

@category.products.with_any_tags(['tag1', 'tag2']) => products tagged with one or both

@category.products.without_tags(['tag1', 'tag2']) => products not with any of tags