Orbit/lib/orbit_basis.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

module OrbitBasis
2012-11-12 02:41:41 +00:00
module RenderAnywhere
def render_anywhere(partial,opts)
view = ActionView::Base.new(Orbit::Application.config.paths["app/views"].first)
view.extend ApplicationHelper
view.render(:partial => partial,:locals=>opts)
end
end
module BaseModel
extend ActiveSupport::Concern
# included do
# scope :recent, desc(:_id)
# scope :exclude_ids, Proc.new { |ids| where(:_id.nin => ids.map(&:to_i)) }
# scope :by_week, where(:created_at.gte => 7.days.ago.utc)
# end
module ClassMethods
def find_in_batches(opts = {})
batch_size = opts[:batch_size] || 1000
start = opts.delete(:start).to_i || 0
objects = self.limit(batch_size).skip(start)
t = Time.new
while objects.any?
yield objects
start += batch_size
# Rails.logger.debug("processed #{start} records in #{Time.new - t} seconds") if Rails.logger.debug?
break if objects.size < batch_size
objects = self.limit(batch_size).skip(start)
end
end
end
end
end