Class: Extface::Device

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/extface/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#driver ⇒ Object



20
21
22
# File 'app/models/extface/device.rb', line 20

def driver
  driveable.try(:class)
end

Instance Method Details

#driver_name ⇒ Object



24
25
26
# File 'app/models/extface/device.rb', line 24

def driver_name
  driver::NAME if driver
end

#session(description = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/extface/device.rb', line 28

def session(description = nil)
  job = jobs.create!(description: description)
  Thread.new do
    begin
      raise 'No driver configured' unless driveable.present?
      driveable.set_job(job)
      yield driveable
      job.complete!
    rescue => e
      STDERR.puts e.message
      e.backtrace.each do |line|
        p line
      end
      job.failed! e.message
    end
  end
  job
end