Module: Draper::Finders
- Defined in:
- lib/draper/finders.rb
Overview
Provides automatically-decorated finder methods for your decorators. You
do not have to extend this module directly; it is extended by
Decorator.decorates_finders.
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Decorates dynamic finder methods (find_all_by_
and friends).
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/draper/finders.rb', line 23
def method_missing(method, *args, &block)
return super unless method =~ /^find_(all_|last_|or_(initialize_|create_))?by_/
result = object_class.send(method, *args, &block)
options = args.
if method =~ /^find_all/
decorate_collection(result, options)
else
decorate(result, options)
end
end
|
Instance Method Details
#all(options = {}) ⇒ Object
10
11
12
|
# File 'lib/draper/finders.rb', line 10
def all(options = {})
decorate_collection(object_class.all, options)
end
|
#find(id, options = {}) ⇒ Object
6
7
8
|
# File 'lib/draper/finders.rb', line 6
def find(id, options = {})
decorate(object_class.find(id), options)
end
|
#first(options = {}) ⇒ Object
14
15
16
|
# File 'lib/draper/finders.rb', line 14
def first(options = {})
decorate(object_class.first, options)
end
|
#last(options = {}) ⇒ Object
18
19
20
|
# File 'lib/draper/finders.rb', line 18
def last(options = {})
decorate(object_class.last, options)
end
|