Low commit activity in last 3 years
A long-lived project that still receives updates
Easily maintain a collection of Tag instances with aggregate counts from your model's tags.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Mongoid::TagCollectible

Gem Version Test Coverage Status

The Ruby 4.0 CI job measures library line coverage with SimpleCov and submits coverage/.resultset.json to Coveralls using GitHub's automatic token. Other matrix jobs do not submit duplicate reports. Run COVERAGE=true bundle install followed by COVERAGE=true bundle exec rake spec for a local report. The default-branch badge requires Coveralls to accept an upstream master build; configuring this workflow does not activate the external service.

Easily maintain a collection of Tag instances with aggregate counts from your model's tags.

Installation

Add mongoid-tag-collectible to your Gemfile.

gem 'mongoid-tag-collectible'

Usage

class Thing
  include Mongoid::Document
  include Mongoid::TagCollectible::Tagged
end

thing1 = Thing.create!(tags: %w[funny red])
thing2 = Thing.create!(tags: %w[funny yellow])

funny_tag = ThingTag.find('funny') # find by tag
funny_tag.name # "funny"
funny_tag.count # 2, not a database query
funny_tag.tagged # thing1 and thing2

Renaming Tags

You can rename a tag, which causes all the tags in your model's tags collection to be renamed.

ThingTag.find('funny').update_attributes!(name: 'sad')

Thing.first.tags # [ 'sad', 'red' ]

Destroying Tags

You can destroy a tag, which also removes it from your model's tags collection.

ThingTag.find('red').destroy
Thing.first.tags # [ 'sad' ]

Case-Sensitive

Tags are case-sensitive. Transform your tags in before_validation if you don't want this behavior.

class Thing
  before_validation :downcase_tags

  private

  def downcase_tags
    tags = tags.map(&:downcase) if tags
  end
end

Contributing

See CONTRIBUTING.md, CHANGELOG.md, and RELEASING.md.

Copyright and License

Copyright Daniel Doubrovkine and Contributors, Artsy Inc., 2013-2015

MIT License