Class: SimpleQuery::LimitOffsetClause
- Inherits:
-
Object
- Object
- SimpleQuery::LimitOffsetClause
- Defined in:
- lib/simple_query/clauses/limit_offset_clause.rb
Instance Attribute Summary collapse
-
#limit_value ⇒ Object
readonly
Returns the value of attribute limit_value.
-
#offset_value ⇒ Object
readonly
Returns the value of attribute offset_value.
Instance Method Summary collapse
- #apply_to(query) ⇒ Object
-
#initialize ⇒ LimitOffsetClause
constructor
A new instance of LimitOffsetClause.
- #with_limit(limit) ⇒ Object
- #with_offset(offset) ⇒ Object
Constructor Details
#initialize ⇒ LimitOffsetClause
Returns a new instance of LimitOffsetClause.
7 8 9 10 |
# File 'lib/simple_query/clauses/limit_offset_clause.rb', line 7 def initialize @limit_value = nil @offset_value = nil end |
Instance Attribute Details
#limit_value ⇒ Object (readonly)
Returns the value of attribute limit_value.
5 6 7 |
# File 'lib/simple_query/clauses/limit_offset_clause.rb', line 5 def limit_value @limit_value end |
#offset_value ⇒ Object (readonly)
Returns the value of attribute offset_value.
5 6 7 |
# File 'lib/simple_query/clauses/limit_offset_clause.rb', line 5 def offset_value @offset_value end |
Instance Method Details
#apply_to(query) ⇒ Object
24 25 26 27 28 |
# File 'lib/simple_query/clauses/limit_offset_clause.rb', line 24 def apply_to(query) query.take(@limit_value) if @limit_value query.skip(@offset_value) if @offset_value query end |
#with_limit(limit) ⇒ Object
12 13 14 15 16 |
# File 'lib/simple_query/clauses/limit_offset_clause.rb', line 12 def with_limit(limit) raise ArgumentError, "LIMIT must be a positive integer" unless limit.is_a?(Integer) && limit.positive? @limit_value = limit end |
#with_offset(offset) ⇒ Object
18 19 20 21 22 |
# File 'lib/simple_query/clauses/limit_offset_clause.rb', line 18 def with_offset(offset) raise ArgumentError, "OFFSET must be a non-negative integer" unless offset.is_a?(Integer) && offset >= 0 @offset_value = offset end |