Method: UPnP::Device.create
- Defined in:
- lib/UPnP/device.rb
.create(type, friendly_name, &block) ⇒ Object
Loads a device of type type
and named friendly_name
, or creates a new device from block
and dumps it.
If a dump exists for the same device type and friendly_name the dump is loaded and used as defaults. This preserves the device name (UUID) across device restarts.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/UPnP/device.rb', line 209 def self.create(type, friendly_name, &block) klass = const_get type device_definition = File.join '~', '.UPnP', type, friendly_name device_definition = File. device_definition device = nil if File.exist? device_definition then open device_definition, 'rb' do |io| device = Marshal.load io.read end yield device if block_given? else device = klass.new type, friendly_name, &block end device.dump device rescue NameError => e raise unless e. =~ /UPnP::Service::#{type}/ raise Error, "unknown device type #{type}" end |