Class: ICuke::Simulator
- Inherits:
-
Object
- Object
- ICuke::Simulator
- Includes:
- HTTParty, Timeout
- Defined in:
- lib/icuke/waxsim.rb,
lib/icuke/simulator.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#current_process ⇒ Object
Returns the value of attribute current_process.
Instance Method Summary collapse
- #fire_event(event) ⇒ Object
- #get(path, options = {}) ⇒ Object
- #launch(process) ⇒ Object
- #load(path) ⇒ Object
- #load_module(path) ⇒ Object
- #play ⇒ Object
- #quit ⇒ Object
- #record ⇒ Object
- #resume ⇒ Object
- #save(path) ⇒ Object
- #set_defaults(defaults) ⇒ Object
- #stop ⇒ Object
- #suspend ⇒ Object
- #view ⇒ Object
Instance Attribute Details
#current_process ⇒ Object
Returns the value of attribute current_process.
8 9 10 |
# File 'lib/icuke/waxsim.rb', line 8 def current_process @current_process end |
Instance Method Details
#fire_event(event) ⇒ Object
42 43 44 |
# File 'lib/icuke/simulator.rb', line 42 def fire_event(event) get '/event', :query => event.to_json end |
#get(path, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/icuke/simulator.rb', line 50 def get(path, = {}) [:query] = URI.escape([:query]) if .has_key?(:query) response = self.class.get(path, ) if response.code != 200 raise Simulator::Error, response.body end response.body end |
#launch(process) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/icuke/waxsim.rb', line 10 def launch(process) process = process.({ :env => { 'CFFIXED_USER_HOME' => Dir.mktmpdir } }) process.setup_commands.each do |cmd| fail "Unable to run setup command #{cmd}" if !system(cmd) fail "Setup command #{cmd} failed with exit status #{$?}" if $? != 0 end @simulator = BackgroundProcess.run(process.command) self.current_process = process timeout(30) do begin view rescue Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError sleep(0.5) retry end end end |
#load(path) ⇒ Object
30 31 32 |
# File 'lib/icuke/simulator.rb', line 30 def load(path) get '/load', :query => path end |
#load_module(path) ⇒ Object
38 39 40 |
# File 'lib/icuke/simulator.rb', line 38 def load_module(path) get '/module', :query => path end |
#play ⇒ Object
34 35 36 |
# File 'lib/icuke/simulator.rb', line 34 def play get '/play' end |
#quit ⇒ Object
35 36 37 38 39 40 |
# File 'lib/icuke/waxsim.rb', line 35 def quit return unless @simulator get '/quit' rescue nil # results in a hard exit(0) @simulator.wait self.current_process = nil end |
#record ⇒ Object
18 19 20 |
# File 'lib/icuke/simulator.rb', line 18 def record get '/record' end |
#resume ⇒ Object
48 49 50 |
# File 'lib/icuke/waxsim.rb', line 48 def resume launch(self.current_process) end |
#save(path) ⇒ Object
26 27 28 |
# File 'lib/icuke/simulator.rb', line 26 def save(path) get '/save', :query => path end |
#set_defaults(defaults) ⇒ Object
46 47 48 |
# File 'lib/icuke/simulator.rb', line 46 def set_defaults(defaults) get '/defaults', :query => defaults.to_json end |
#stop ⇒ Object
22 23 24 |
# File 'lib/icuke/simulator.rb', line 22 def stop get '/stop' end |
#suspend ⇒ Object
42 43 44 45 46 |
# File 'lib/icuke/waxsim.rb', line 42 def suspend @simulator.kill('QUIT') # invokes the normal app exit routine @simulator.wait sleep 1 end |
#view ⇒ Object
14 15 16 |
# File 'lib/icuke/simulator.rb', line 14 def view get('/view') end |