Module: Axiom::Relation::Operation::Limit::Methods
- Defined in:
- lib/axiom/relation/operation/limit.rb
Constant Summary collapse
- DEFAULT_ONE_BLOCK =
Default block used in #one
-> {}
- ONE_LIMIT =
Maximum number of tuples to take in #one
2
Instance Method Summary collapse
-
#first(limit = 1) ⇒ Limit
Return a relation with the first n tuples.
-
#last(limit = 1) ⇒ Limit
Return a relation with the last n tuples.
-
#one(&block) ⇒ Tuple
Return a tuple if the relation contains exactly one tuple.
-
#take(limit) ⇒ Limit
Return a relation with n tuples.
Instance Method Details
#first(limit = 1) ⇒ Limit
Return a relation with the first n tuples
188 189 190 |
# File 'lib/axiom/relation/operation/limit.rb', line 188 def first(limit = 1) take(limit) end |
#last(limit = 1) ⇒ Limit
Return a relation with the last n tuples
206 207 208 |
# File 'lib/axiom/relation/operation/limit.rb', line 206 def last(limit = 1) reverse.take(limit).reverse end |
#one(&block) ⇒ Tuple
Return a tuple if the relation contains exactly one tuple
228 229 230 231 232 233 234 |
# File 'lib/axiom/relation/operation/limit.rb', line 228 def one(&block) block ||= DEFAULT_ONE_BLOCK tuples = take(ONE_LIMIT).to_a assert_no_more_than_one_tuple(tuples.size) tuples.first or block.yield or fail NoTuplesError, 'one tuple expected, but was an empty set' end |