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

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

Instance Method Summary collapse

Instance Method Details

#all_sequentially(&block) ⇒ Object

Sequentiall :all for big collection



32
33
34
35
36
37
38
39
# File 'lib/mongo_mapper_ext/plugins/micelaneous.rb', line 32

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



20
21
22
23
24
25
26
# File 'lib/mongo_mapper_ext/plugins/micelaneous.rb', line 20

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



45
46
47
48
# File 'lib/mongo_mapper_ext/plugins/micelaneous.rb', line 45

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