Sha256: 955dedec06adcac62bd584739211c83fc6c6ad56b5dadd2b9b1f46b2f323b993
Contents?: true
Size: 1.18 KB
Versions: 4
Compression:
Stored size: 1.18 KB
Contents
module Extface class Device < ActiveRecord::Base attr_writer :driver belongs_to :extfaceable, polymorphic: true belongs_to :driveable, polymorphic: true has_many :jobs, inverse_of: :device accepts_nested_attributes_for :driveable delegate :print?, :fiscal?, :raw?, :cdr?, to: :driveable, allow_nil: true validates_uniqueness_of :name, :uuid, scope: [:extfaceable_id, :extfaceable_type] before_create do self.uuid = SecureRandom.hex self.name = uuid unless name.present? self.driveable = @driver.constantize.create if @driver.present? end def driver driveable.try(:class) end def driver_name driver::NAME if driver end 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 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
extface-0.0.5 | app/models/extface/device.rb |
extface-0.0.3 | app/models/extface/device.rb |
extface-0.0.2 | app/models/extface/device.rb |
extface-0.0.1 | app/models/extface/device.rb |