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

Version 2.0.0: Multiple aggregations, scopes, Strategy API #10

Open johnnyshields opened 11 years ago

johnnyshields commented 11 years ago

@lgs I'm working on a version 2.0.0 of this gem.

It will allow you do this:

class Person
  include Mongoid::Document
  include Mongoid::Taggable

  field :foo, type: String

  # taggable stays basically the same as 1.1.1
  taggable   # :tags
  taggable :interests, separator: ','
  taggable :skills

  # new taggregation method to define aggregation rules
  taggregation :tags
  taggregation :interests, :tags, strategy: Mongoid::Taggable::Strategy::RealTime, group_by: :foo
  taggregation :tags, strategy: CustomMapReduce, group_by: :foo, scope: -->{ any_in(status: :active) }, name: "active_%{context}"
end

As part of this change, the aggregation strategies will now become classes (currently they are modules). They must inherit the Strategy class which provides a base API for creating rules.

# custom strategies are now possible
class CustomMapReduce < Mongoid::Taggable::Strategy
    def tags
       # must be implemented
    end
    def tags_with_weight
       # must be implemented
    end
end

One change, from 2.0.0 I'd like to use the following shorter namespaces:

Mongoid::Taggable  # this is only one that needs to be included in the Model.
Mongoid::Taggable::Aggregation
Mongoid::Taggable::Strategy

Code is 70% done.

lgs commented 11 years ago

@johnnyshields 2.0.0 version and new aggregation strategies looks great.

johnnyshields commented 10 years ago

This is still on my todo list. I'm actually planning to resume it a month or two as I'll need it for my app. I have a branch going.