Sha256: 57f35499c62677abc40363b60d922ca99ed225a83b25195f73ce9fa4e7ad31fd

Contents?: true

Size: 820 Bytes

Versions: 13

Compression:

Stored size: 820 Bytes

Contents

module MongoMapperExt
  module Tags
    def self.included(klass)
      klass.class_eval do
        extend ClassMethods

        key :tags, Array, :index => true
      end
    end

    module ClassMethods
      def tag_cloud(conditions = {}, limit = 30)
        self.database.eval("function(collection, q,l) { return tag_cloud(collection, q,l); }", self.collection_name, conditions, limit)
      end

      # Model.find_with_tags("budget", "big", :limit => 4)
      def find_with_tags(*tags)
        options = tags.extract_options!
        self.all(options.merge(:tags => tags))
      end

      def find_tags(regex, conditions = {}, limit = 30)
        self.database.eval("function(collection, a,b,c) { return find_tags(collection, a,b,c); }", self.collection_name, regex, conditions, limit)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mongomapper_ext-0.5.2 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.5.1 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.5.0 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.4.0 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.3.0 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.2.4 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.2.3 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.2.2 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.2.1 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.2.0 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.1.5 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.1.4 lib/mongomapper_ext/tags.rb
mongomapper_ext-0.1.3 lib/mongomapper_ext/tags.rb