Module: Orocos::Namespace
- Included in:
- Async::NameServiceBase, Async::TaskContextProxy, CORBA::NameService, Local::NameService, Log::Replay, Log::TaskContext, NameService, ROS::NameService, TaskContextBase
- Defined in:
- lib/orocos/namespace.rb
Overview
The Namespace mixin provides collection classes with several methods for namespace handling.
Constant Summary collapse
- DELIMATOR =
The Delimator between the namespace and the basename.
"/"
Class Method Summary collapse
-
.split_name(name) ⇒ Array<String, String>
Splits the given name into its namespace name and basename.
-
.validate_namespace_name(name) ⇒ Object
Validates that the given name can be used as a namespace name.
Instance Method Summary collapse
-
#basename(name) ⇒ String
Returns the basename of the given name.
-
#map_to_namespace(names) ⇒ String, Array
Maps all given names to this namespace by adding the name of this namespace to the beginning of each given name if name is in none or in a different namespace.
-
#namespace ⇒ String
Returns the name of the used namespace.
-
#namespace=(name) ⇒ Object
Sets the namespace name.
-
#same_namespace?(name) ⇒ Boolean
Checks if the given name is in the same namespace.
-
#split_name(name) ⇒ Array<String, String>
Splits the given name into its namespace name and basename.
-
#verify_same_namespace(name) ⇒ nil
Checks if the given name is in the same namespace and raises an ArgumentError if not.
Class Method Details
.split_name(name) ⇒ Array<String, String>
Splits the given name into its namespace name and basename.
95 96 97 98 99 100 101 |
# File 'lib/orocos/namespace.rb', line 95 def self.split_name(name) if(nil != (name =~ Regexp.new("^(.*)#{DELIMATOR}(.*)$"))) [$1, $2] else [nil, name] end end |
.validate_namespace_name(name) ⇒ Object
Validates that the given name can be used as a namespace name
The only constraint so far is that namespace names cannot contain the namespace-to-name separation character DELIMATOR
110 111 112 113 114 |
# File 'lib/orocos/namespace.rb', line 110 def self.validate_namespace_name(name) if name =~ /#{DELIMATOR}/ raise ArgumentError, "namespace #{name} contains #{DELIMATOR} which is not support." end end |
Instance Method Details
#basename(name) ⇒ String
Returns the basename of the given name.
78 79 80 81 |
# File 'lib/orocos/namespace.rb', line 78 def basename(name) _,name = split_name(name) name end |
#map_to_namespace(names) ⇒ String, Array
Maps all given names to this namespace by adding the name of this namespace to the beginning of each given name if name is in none or in a different namespace.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/orocos/namespace.rb', line 30 def map_to_namespace(names) if !namespace return names end ary = Array(names) ary.map! do |n| _,name = split_name(n) "#{namespace}#{DELIMATOR}#{name}" end if names.is_a? Array ary else ary.first end end |
#namespace ⇒ String
Returns the name of the used namespace.
20 21 22 |
# File 'lib/orocos/namespace.rb', line 20 def namespace @namespace end |
#namespace=(name) ⇒ Object
Sets the namespace name.
12 13 14 15 |
# File 'lib/orocos/namespace.rb', line 12 def namespace=(name) Namespace.validate_namespace_name(name) @namespace = name end |
#same_namespace?(name) ⇒ Boolean
Checks if the given name is in the same namespace.
52 53 54 55 56 57 58 59 |
# File 'lib/orocos/namespace.rb', line 52 def same_namespace?(name) ns,_ = split_name(name) if(!ns || !namespace || ns == namespace) true else false end end |
#split_name(name) ⇒ Array<String, String>
Splits the given name into its namespace name and basename.
87 88 89 |
# File 'lib/orocos/namespace.rb', line 87 def split_name(name) Namespace.split_name name end |
#verify_same_namespace(name) ⇒ nil
Checks if the given name is in the same namespace and raises an ArgumentError if not.
67 68 69 70 71 72 |
# File 'lib/orocos/namespace.rb', line 67 def verify_same_namespace(name) if !same_namespace?(name) ns,_ = split_name(name) raise ArgumentError, "namespace '#{namespace}' was expected but got '#{ns}' for name '#{name}'" end end |