Sha256: 97c308397e32bbd2fb34a91b13adfbeca554eb1b325ca93688be263232064bb7
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
module Sandboxy module Sandboxed def self.included base base.extend ClassMethods end module ClassMethods 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 } # before_save :make_sandboxed # -> should be handled automatically through default_scope end end module InstanceMethods def make_sandboxed self.build_sandbox unless self.sandbox.present? end def make_live self.sandbox.destroy if self.sandbox.present? end def sandboxed? self.sandbox.present? end def live? !self.sandbox.present? end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sandboxy-1.0.0 | lib/sandboxy/sandboxed.rb |