Module: NoBrainer::Criteria::First
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/no_brainer/criteria/first.rb
Instance Method Summary collapse
Instance Method Details
#first ⇒ Object
4 5 6 |
# File 'lib/no_brainer/criteria/first.rb', line 4 def first get_one(self) end |
#first! ⇒ Object
12 13 14 |
# File 'lib/no_brainer/criteria/first.rb', line 12 def first! first || (raise NoBrainer::Error::DocumentNotFound) end |
#last ⇒ Object
8 9 10 |
# File 'lib/no_brainer/criteria/first.rb', line 8 def last get_one(self.reverse_order) end |
#last! ⇒ Object
16 17 18 |
# File 'lib/no_brainer/criteria/first.rb', line 16 def last! last || (raise NoBrainer::Error::DocumentNotFound) end |
#sample(n = nil) ⇒ Object
20 21 22 23 24 |
# File 'lib/no_brainer/criteria/first.rb', line 20 def sample(n=nil) result = run { self.without_ordering.to_rql.sample(n.nil? ? 1 : n) } result = result.map(&method(:instantiate_doc)) n.nil? ? result.first : result end |