10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/sandboxy/sandboxed.rb', line 10
def sandboxy
has_one :sandbox, as: :sandboxed, dependent: :destroy
include Sandboxy::Sandboxed::InstanceMethods
scope :live_scoped, -> { left_outer_joins(:sandbox).where(sandbox: { id: nil }) }
scope :sandboxed_scoped, -> { left_outer_joins(:sandbox).where.not(sandbox: { id: nil }) }
default_scope {
case $sandbox
when true then sandboxed_scoped
when false then live_scoped
end
}
scope :live, -> { unscope(:joins, :where).live_scoped }
scope :sandboxed, -> { unscope(:joins, :where).sandboxed_scoped }
scope :desandbox, -> { unscope(:joins, :where).all }
end
|