Sha256: 411115028f4b40fea91478c652c0e2a9e0d753a97cfac768df3436988d3b5f83
Contents?: true
Size: 683 Bytes
Versions: 3
Compression:
Stored size: 683 Bytes
Contents
module Ambition module Limit def first(limit = 1, offset = nil) query_context.add LimitProcessor.new(limit, offset) find(limit == 1 ? :first : :all, query_context.to_hash) end def [](offset, limit = nil) return first(offset, limit) if limit if offset.is_a? Range limit = offset.end limit -= 1 if offset.exclude_end? first(offset.first, limit - offset.first) else first(offset, 1) end end alias_method :slice, :[] end class LimitProcessor def initialize(*args) @args = args end def key :limit end def to_s @args.compact * ', ' end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ambition-0.1.3 | ./lib/ambition/limit.rb |
ambition-0.1.4 | ./lib/ambition/limit.rb |
ambition-0.1.5 | ./lib/ambition/limit.rb |