9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/dynamic_default_scoping.rb', line 9
def default_scope name, options = nil
if options.present?
scope name, options
else
name, options = nil, name
end
reset_scoped_methods
scoping = self.default_scoping.dup
last = scoping.pop
scope = if last.respond_to?(:call) || options.respond_to?(:call)
lambda do
construct_finder_arel \
options.respond_to?(:call) ? options.call : options,
last.respond_to?(:call) ? last.call : last
end
else
construct_finder_arel options, last
end
self.default_scoping = scoping << scope
end
|