Sha256: 62248c4970709d60b5faf94c25319b63a273efa359fb7a73247531a4f2ccff72

Contents?: true

Size: 904 Bytes

Versions: 2

Compression:

Stored size: 904 Bytes

Contents

# 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
  # 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(s)
      unless self.class.valid?(s)
        raise DBus::Error, "Invalid bus name #{s.inspect}"
      end
      super
    end

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-dbus-0.17.0 lib/dbus/bus_name.rb
ruby-dbus-0.16.0 lib/dbus/bus_name.rb