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).
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/draper/finders.rb', line 24
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
11
12
13
|
# File 'lib/draper/finders.rb', line 11
def all(options = {})
decorate_collection(object_class.all, options)
end
|
#find(id, options = {}) ⇒ Object
7
8
9
|
# File 'lib/draper/finders.rb', line 7
def find(id, options = {})
decorate(object_class.find(id), options)
end
|
#first(options = {}) ⇒ Object
15
16
17
|
# File 'lib/draper/finders.rb', line 15
def first(options = {})
decorate(object_class.first, options)
end
|
#last(options = {}) ⇒ Object
19
20
21
|
# File 'lib/draper/finders.rb', line 19
def last(options = {})
decorate(object_class.last, options)
end
|