Sha256: f5a58c11e3fb2a729f199b858089ee56ca8a7ee897ef8b99bd3c3593add2a53c

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

module MongoModel::MapReduce
  extend ActiveSupport::Concern
  
  include MongoModel::DocumentExtensions::Scopes
  
  included do
    class_attribute :parent_collection
  end
  
  module ClassMethods
    def from_mongo(attrs)
      new(attrs['_id'], attrs['value'])
    end
    
    def cached
      from(collection_name)
    end
    
    def database
      parent_collection.db
    end
    
    def collection
      parent_collection.map_reduce(map_function, reduce_function, map_reduce_options)
    end
    
    def collection_name
      @_collection_name || default_collection_name
    end
    
    def collection_name=(name)
      @_collection_name = name
    end
    
    def default_collection_name
      [parent_collection.name, name.demodulize.tableize.gsub(/\//, '.')].join("._")
    end
    
    def map_function
      raise NotImplementedError, "map_function is not implemented"
    end
    
    def reduce_function
      raise NotImplementedError, "reduce_function is not implemented"
    end

    def map_reduce_options
      { :out => collection_name }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongomodel-0.5.5 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.5.4 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.5.3 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.5.2 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.5.1 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.5.0 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.4.9 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.4.8 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.4.7 lib/mongomodel/concerns/map_reduce.rb
mongomodel-0.4.6 lib/mongomodel/concerns/map_reduce.rb