Module: DTK::Client::ModuleUtil
- Defined in:
- lib/util/module_util.rb
Constant Summary collapse
- NAMESPACE_SEPERATOR =
':'
Class Method Summary collapse
- .check_format!(module_identifier) ⇒ Object
- .filter_module_name(name_or_full_module_name) ⇒ Object
-
.full_module_name_parts?(name_or_full_module_name) ⇒ Boolean
returns [namespace,name]; namespace can be null if cant determine it.
- .join_name(module_name, module_namespace) ⇒ Object
- .module_name(module_type) ⇒ Object
- .resolve_name(module_name, module_namespace) ⇒ Object
- .type_to_sym(module_type_s) ⇒ Object
Class Method Details
.check_format!(module_identifier) ⇒ Object
55 56 57 58 59 |
# File 'lib/util/module_util.rb', line 55 def self.check_format!(module_identifier) return module_identifier if module_identifier.match(/^[0-9]+$/) DtkLogger.instance.debug(caller) raise DtkError, "Module name should be in following format NAMESPACE#{NAMESPACE_SEPERATOR}MODULE_NAME" unless module_identifier.match(Regexp.new("^.+#{NAMESPACE_SEPERATOR}.+$")) end |
.filter_module_name(name_or_full_module_name) ⇒ Object
51 52 53 |
# File 'lib/util/module_util.rb', line 51 def self.filter_module_name(name_or_full_module_name) full_module_name_parts?(name_or_full_module_name).last end |
.full_module_name_parts?(name_or_full_module_name) ⇒ Boolean
returns [namespace,name]; namespace can be null if cant determine it
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/util/module_util.rb', line 39 def self.full_module_name_parts?(name_or_full_module_name) if name_or_full_module_name.nil? return [nil,nil] end if name_or_full_module_name =~ Regexp.new("(^.+)#{NAMESPACE_SEPERATOR}(.+$)") namespace,name = [$1,$2] else namespace,name = [nil,name_or_full_module_name] end [namespace,name] end |
.join_name(module_name, module_namespace) ⇒ Object
30 31 32 |
# File 'lib/util/module_util.rb', line 30 def self.join_name(module_name, module_namespace) module_namespace ? resolve_name(module_name, module_namespace) : module_name end |
.module_name(module_type) ⇒ Object
34 35 36 |
# File 'lib/util/module_util.rb', line 34 def self.module_name(module_type) module_type.to_s.gsub('_',' ') end |
.resolve_name(module_name, module_namespace) ⇒ Object
24 25 26 27 28 |
# File 'lib/util/module_util.rb', line 24 def self.resolve_name(module_name, module_namespace) is_invalid = module_name.nil? || module_namespace.nil? || module_name.empty? || module_namespace.empty? raise DtkError, "Failed to provide module name (#{module_name}) or namespace (#{module_namespace})" if is_invalid "#{module_namespace}#{NAMESPACE_SEPERATOR}#{module_name}" end |
.type_to_sym(module_type_s) ⇒ Object
61 62 63 |
# File 'lib/util/module_util.rb', line 61 def self.type_to_sym(module_type_s) module_type_s.to_s.gsub!(/\_/,'-').to_sym end |