Class: Ambition::Adapters::ActiveRecord::Slice

Inherits:
Base
  • Object
show all
Defined in:
lib/ambition/adapters/active_record/slice.rb

Instance Method Summary collapse

Methods inherited from Base

#active_connection?, #dbadapter_name, #quote_column_name, #sanitize, #statement

Instance Method Details

#slice(start, length = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ambition/adapters/active_record/slice.rb', line 5

def slice(start, length=nil)
  if start.is_a? Range
    length  = start.end
    length -= 1 if start.exclude_end?
    start = start.first - 1
    length -= start
  end
  out  = "LIMIT #{length} "
  out << "OFFSET #{start}" if start.to_i.nonzero?
  out
end