13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/toqua/scoping.rb', line 13
def __run_scope(relation, scope, opts)
if_condition = if opts[:if]
opts[:if].respond_to?(:call) ? !!instance_exec(&opts[:if]) : send(opts[:if])
elsif opts[:unless]
opts[:unless].respond_to?(:call) ? !instance_exec(&opts[:unless]) : !send(opts[:unless])
else
true
end
action_condition = if opts[:only]
[opts[:only]].flatten.include?(action_name.to_sym)
else
true
end
if if_condition && action_condition
self.instance_exec(relation, &scope)
else
relation
end
end
|