Module: NullRecord::FinderMethods::ClassMethods

Defined in:
lib/null_record/finder_methods.rb

Instance Method Summary collapse

Instance Method Details

#fifthObject



6
7
8
# File 'lib/null_record/finder_methods.rb', line 6

def fifth
  super || null_object
end

#find(id) ⇒ Object



10
11
12
13
14
# File 'lib/null_record/finder_methods.rb', line 10

def find(id)
  super(id)
rescue ActiveRecord::RecordNotFound
  null_object
end

#find_by(attributes) ⇒ Object



16
17
18
# File 'lib/null_record/finder_methods.rb', line 16

def find_by(attributes)
  super(attributes) || null_object
end

#firstObject



20
21
22
# File 'lib/null_record/finder_methods.rb', line 20

def first
  super || null_object
end

#forty_twoObject



24
25
26
# File 'lib/null_record/finder_methods.rb', line 24

def forty_two
  super || null_object
end

#fourthObject



28
29
30
# File 'lib/null_record/finder_methods.rb', line 28

def fourth
  super || null_object
end

#lastObject



32
33
34
# File 'lib/null_record/finder_methods.rb', line 32

def last
  super || null_object
end

#secondObject



36
37
38
# File 'lib/null_record/finder_methods.rb', line 36

def second
  super || null_object
end

#take(limit = nil) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/null_record/finder_methods.rb', line 40

def take(limit = nil)
  if limit && limit > 1
    result = super(limit)
    result.size > 1 ? result : Array.new(limit) { null_object }
  else
    super(limit) || null_object
  end
end

#thirdObject



49
50
51
# File 'lib/null_record/finder_methods.rb', line 49

def third
  super || null_object
end