Git Product home page Git Product logo

mongoid_tag's Introduction

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

mongoid_tag's People

Contributors

christianhager avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

rocknrollmarc

mongoid_tag's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.