Module: MongoMapper::Plugins::Micelaneous::ClassMethods

Defined in:
lib/mongo_mapper_ext/mongo_mapper/plugins/micelaneous.rb

Instance Method Summary collapse

Instance Method Details

#all_sequentially(&block) ⇒ Object

Sequentiall :all for big collection



30
31
32
33
34
35
36
37
# File 'lib/mongo_mapper_ext/mongo_mapper/plugins/micelaneous.rb', line 30

def all_sequentially &block
  page, per_page = 1, 5
  begin
    results = paginate(page: page, per_page: per_page, order: '_id asc')
    results.each{|o| block.call o}
    page += 1
  end until results.blank? or results.size < per_page
end

#model_name(*args) ⇒ Object

model_name



18
19
20
21
22
23
24
# File 'lib/mongo_mapper_ext/mongo_mapper/plugins/micelaneous.rb', line 18

def model_name *args
  if args.empty?
    @model_name ||= ::ActiveModel::Name.new self, self.alias
  else
    @model_name = ::ActiveModel::Name.new self, args.first
  end          
end

#upsert!(query, *args) ⇒ Object

shortcut for upsert



43
44
45
46
# File 'lib/mongo_mapper_ext/mongo_mapper/plugins/micelaneous.rb', line 43

def upsert! query, *args
  query[:_id] = query.delete :id if query.include? :id
  collection.upsert! query, *args          
end