Module: Mongoid::Miscellaneous::ClassMethods
- Defined in:
- lib/mongoid_misc/miscellaneous.rb
Instance Method Summary collapse
-
#all_sequentially(&block) ⇒ Object
Sequentiall :all for big collection.
-
#model_name(*args) ⇒ Object
model_name.
- #to_param ⇒ Object
-
#upsert!(query, *args) ⇒ Object
shortcut for upsert.
Instance Method Details
#all_sequentially(&block) ⇒ Object
Sequentiall :all for big collection
56 57 58 59 60 61 62 63 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 56 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
44 45 46 47 48 49 50 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 44 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 |
#to_param ⇒ Object
75 76 77 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 75 def to_param (id || '').to_s end |
#upsert!(query, *args) ⇒ Object
shortcut for upsert
69 70 71 72 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 69 def upsert! query, *args query[:_id] = query.delete :id if query.include? :id collection.upsert! query, *args end |