Class: Shikashi::Sandbox::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/shikashi/sandbox.rb

Instance Method Summary collapse

Constructor Details

#initialize(evalhook_packet, default_privileges, source) ⇒ Packet

:nodoc:



107
108
109
110
111
# File 'lib/shikashi/sandbox.rb', line 107

def initialize(evalhook_packet, default_privileges, source) #:nodoc:
  @evalhook_packet = evalhook_packet
  @default_privileges = default_privileges
  @source = source
end

Instance Method Details

#disposeObject

Dispose the objects associated with this code package



138
139
140
# File 'lib/shikashi/sandbox.rb', line 138

def dispose
  @evalhook_packet.dispose
end

#run(*args) ⇒ Object

Run the code in the package

call-seq: run(arguments)

Arguments

:binding Optional argument with the binding object of the context where the code is to be executed

The default is a binding in the global context

:timeout Optional argument to restrict the execution time of the script to a given value in seconds



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/shikashi/sandbox.rb', line 122

def run(*args)
  t = args.pick(:timeout) do nil end
  binding_ = args.pick(Binding,:binding) do
    nil
  end

  begin
    timeout t do
      @evalhook_packet.run(binding_, @source, 0)
    end
  rescue ::Timeout::Error
    raise Shikashi::Timeout::Error
  end
end