module Sandboxy::Sandboxed::SandboxyInstanceMethods

Public Instance Methods

environment() click to toggle source
# File lib/sandboxy/sandboxed.rb, line 85
def environment
  return Sandboxy.configuration.default if sandbox.nil?

  sandbox.environment
end
environment?(value) click to toggle source
# File lib/sandboxy/sandboxed.rb, line 81
def environment?(value)
  environment == value
end
method_missing(method, *args) click to toggle source
Calls superclass method
# File lib/sandboxy/sandboxed.rb, line 56
def method_missing(method, *args)
  if method.to_s[/move_environment_(.+)/]
    move_environment($1)
  elsif method.to_s[/(.+)_environment?/]
    environment?($1)
  else
    super
  end
end
move_environment(environment) click to toggle source
# File lib/sandboxy/sandboxed.rb, line 72
def move_environment(environment)
  case environment
  when Sandboxy.configuration.default
    move_to_default_environment
  else
    move_to_custom_environment(environment)
  end
end
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/sandboxy/sandboxed.rb, line 66
def respond_to_missing?(method, include_private = false)
  super ||
    method.to_s[/move_environment_(.+)/] ||
    method.to_s[/(.+)_environment?/]
end

Private Instance Methods

move_to_custom_environment(environment) click to toggle source
# File lib/sandboxy/sandboxed.rb, line 107
def move_to_custom_environment(environment)
  sandbox ||= build_sandbox
  sandbox.environment = environment
  sandbox.save!
end
move_to_default_environment() click to toggle source
# File lib/sandboxy/sandboxed.rb, line 100
def move_to_default_environment
  Sandbox.where(sandboxed_id: id, sandboxed_type: self.class.name)
         .destroy_all
  self.sandbox = nil
  save!
end
set_environment() click to toggle source
# File lib/sandboxy/sandboxed.rb, line 93
def set_environment
  return if Sandboxy.environment == Sandboxy.configuration.default

  sandbox = build_sandbox
  sandbox.environment = Sandboxy.environment
end