Class: DBus::Type::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/dbus/type.rb

Direct Known Subclasses

ArrayFactory, HashFactory, StructFactory

Class Method Summary collapse

Class Method Details

.from_plain_class(klass) ⇒ Type

Make a Type corresponding to some plain classes:

  • String

  • Float

  • DBus::ObjectPath

  • DBus::Signature, DBus::SingleCompleteType

Parameters:

Returns:

  • (Type)

    (frozen)

Raises:

  • (ArgumentError)


309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/dbus/type.rb', line 309

def self.from_plain_class(klass)
  @signature_type ||= DBus.type(SIGNATURE)
  @class_to_type ||= {
    DBus::ObjectPath => DBus.type(OBJECT_PATH),
    DBus::Signature => @signature_type,
    DBus::SingleCompleteType => @signature_type,
    String => DBus.type(STRING),
    Float => DBus.type(DOUBLE)
  }
  t = @class_to_type[klass]
  raise ArgumentError, "Cannot convert plain class #{klass} to a D-Bus type" if t.nil?

  t
end

.make_type(type) ⇒ Type

Returns (frozen).

Parameters:

Returns:

  • (Type)

    (frozen)

See Also:



288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/dbus/type.rb', line 288

def self.make_type(type)
  case type
  when Type
    type
  when String
    DBus.type(type)
  when Class
    from_plain_class(type)
  else
    msg = "Expecting DBus::Type, DBus::SingleCompleteType(aka ::String), or Class, got #{type.inspect}"
    raise ArgumentError, msg
  end
end