lgs / mongoid_taggable_with_context

A tagging plugin for Mongoid that allows for custom tagging along dynamic contexts with real-time aggregation (pre-aggregated).
http://rubygems.org/gems/mongoid_taggable_with_context
MIT License
19 stars 20 forks source link

Tag relations with any instead of all #3

Closed holden closed 11 years ago

holden commented 11 years ago

I want to find related documents using the tags... which wouldn't work with all_in, so I updated it to any_in and it seems to work fine.

Article.tagged_with(['ruby', 'mongodb'])

Maybe this should be an option?

Article.tagged_with(['ruby', 'mongodb'], :match_all => true) Article.tagged_with(['ruby', 'mongodb'], :any => true)

Find documents tagged with all tags passed as a parameter, given

# as an Array or a String using the configured separator.
#
# @example Find matching all tags in an Array.
#   Article.tagged_with(['ruby', 'mongodb'])
# @example Find matching all tags in a String.
#   Article.tagged_with('ruby, mongodb')

def tagged_with(context, tags)
  tags = convert_string_to_array(tags, get_tag_separator_for(context)) if tags.is_a? String
  array_field = tag_options_for(context)[:array_field]
  any_in(array_field => tags)
end
lgs commented 11 years ago

Seems good to me. Could you please add Rspec and pull the request ?

johnnyshields commented 11 years ago

This has been merged already it looks like. We should close this issue.