Sha256: 85fbd797630f55cfee3db0c88aa2397a3d42e64839d4e15b20136da6974f45f2

Contents?: true

Size: 1.03 KB

Versions: 18

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

# This file is part of the ruby-dbus project
# Copyright (C) 2019 Martin Vidner
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License, version 2.1 as published by the Free Software Foundation.
# See the file "COPYING" for the exact licensing terms.

module DBus
  # D-Bus: a name for a connection, like ":1.3" or "org.example.ManagerManager".
  # Implemented as a {::String} that validates at initialization time.
  # @see https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus
  class BusName < String
    # @raise Error if not a valid bus name
    def initialize(name)
      unless self.class.valid?(name)
        raise DBus::Error, "Invalid bus name #{name.inspect}"
      end

      super
    end

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ruby-dbus-0.24.0 lib/dbus/bus_name.rb
ruby-dbus-0.23.1 lib/dbus/bus_name.rb
ruby-dbus-0.23.0.beta2 lib/dbus/bus_name.rb
ruby-dbus-0.23.0.beta1 lib/dbus/bus_name.rb
ruby-dbus-0.22.1 lib/dbus/bus_name.rb
ruby-dbus-0.22.0 lib/dbus/bus_name.rb
ruby-dbus-0.21.0 lib/dbus/bus_name.rb
ruby-dbus-0.20.0 lib/dbus/bus_name.rb
ruby-dbus-0.19.0 lib/dbus/bus_name.rb
ruby-dbus-0.18.1 lib/dbus/bus_name.rb
ruby-dbus-0.18.0.beta8 lib/dbus/bus_name.rb
ruby-dbus-0.18.0.beta7 lib/dbus/bus_name.rb
ruby-dbus-0.18.0.beta6 lib/dbus/bus_name.rb
ruby-dbus-0.18.0.beta5 lib/dbus/bus_name.rb
ruby-dbus-0.18.0.beta4 lib/dbus/bus_name.rb
ruby-dbus-0.18.0.beta3 lib/dbus/bus_name.rb
ruby-dbus-0.18.0.beta2 lib/dbus/bus_name.rb
ruby-dbus-0.18.0.beta1 lib/dbus/bus_name.rb