Class: DBus::BusName

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

Overview

A String that validates at initialization time

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ BusName

Returns a new instance of BusName.

Raises:

  • Error if not a valid bus name



14
15
16
17
18
19
# File 'lib/dbus/bus_name.rb', line 14

def initialize(s)
  unless self.class.valid?(s)
    raise DBus::Error, "Invalid bus name #{s.inspect}"
  end
  super
end

Class Method Details

.valid?(s) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/dbus/bus_name.rb', line 21

def self.valid?(s)
  s.size <= 255 &&
    (s =~ /\A:[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)+\z/ ||
     s =~ /\A[A-Za-z_-][A-Za-z0-9_-]*(\.[A-Za-z_-][A-Za-z0-9_-]*)+\z/)
end