Module: MongoModel::MapReduce::ClassMethods

Defined in:
lib/mongomodel/concerns/map_reduce.rb

Instance Method Summary collapse

Instance Method Details

#cachedObject



15
16
17
# File 'lib/mongomodel/concerns/map_reduce.rb', line 15

def cached
  from(collection_name)
end

#collectionObject



23
24
25
# File 'lib/mongomodel/concerns/map_reduce.rb', line 23

def collection
  parent_collection.map_reduce(map_function, reduce_function, map_reduce_options)
end

#collection_nameObject



27
28
29
# File 'lib/mongomodel/concerns/map_reduce.rb', line 27

def collection_name
  @_collection_name || default_collection_name
end

#collection_name=(name) ⇒ Object



31
32
33
# File 'lib/mongomodel/concerns/map_reduce.rb', line 31

def collection_name=(name)
  @_collection_name = name
end

#databaseObject



19
20
21
# File 'lib/mongomodel/concerns/map_reduce.rb', line 19

def database
  parent_collection.db
end

#default_collection_nameObject



35
36
37
# File 'lib/mongomodel/concerns/map_reduce.rb', line 35

def default_collection_name
  [parent_collection.name, name.demodulize.tableize.gsub(/\//, '.')].join("._")
end

#from_mongo(attrs) ⇒ Object



11
12
13
# File 'lib/mongomodel/concerns/map_reduce.rb', line 11

def from_mongo(attrs)
  new(attrs['_id'], attrs['value'])
end

#map_functionObject

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/mongomodel/concerns/map_reduce.rb', line 39

def map_function
  raise NotImplementedError, "map_function is not implemented"
end

#map_reduce_optionsObject



47
48
49
# File 'lib/mongomodel/concerns/map_reduce.rb', line 47

def map_reduce_options
  { :out => collection_name }
end

#reduce_functionObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/mongomodel/concerns/map_reduce.rb', line 43

def reduce_function
  raise NotImplementedError, "reduce_function is not implemented"
end