Class: RGen::Serializer::QualifiedNameProvider
- Inherits:
-
Object
- Object
- RGen::Serializer::QualifiedNameProvider
- Defined in:
- lib/rgen/serializer/qualified_name_provider.rb
Overview
simple identifier calculation based on qualified names. as a prerequisit, elements must have a local name stored in single attribute attribute_name
. there may be classes without the name attribute though and there may be elements without a local name. in both cases the element will have the same qualified name as its container.
Instance Method Summary collapse
- #identifier(element) ⇒ Object
-
#initialize(options = {}) ⇒ QualifiedNameProvider
constructor
A new instance of QualifiedNameProvider.
- #qualified_name(element) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ QualifiedNameProvider
Returns a new instance of QualifiedNameProvider.
12 13 14 15 16 17 |
# File 'lib/rgen/serializer/qualified_name_provider.rb', line 12 def initialize(={}) @qualified_name_cache = {} @attribute_name = [:attribute_name] || "name" @separator = [:separator] || "/" @leading_separator = .has_key?(:leading_separator) ? [:leading_separator] : true end |
Instance Method Details
#identifier(element) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rgen/serializer/qualified_name_provider.rb', line 19 def identifier(element) if element.is_a?(RGen::MetamodelBuilder::MMProxy) element.targetIdentifier else qualified_name(element) end end |
#qualified_name(element) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rgen/serializer/qualified_name_provider.rb', line 27 def qualified_name(element) return @qualified_name_cache[element] if @qualified_name_cache[element] local_ident = ((element.respond_to?(@attribute_name) && element.getGeneric(@attribute_name)) || "").strip parent = element.eContainer if parent if local_ident.size > 0 result = qualified_name(parent) + @separator + local_ident else result = qualified_name(parent) end else result = (@leading_separator ? @separator : "") + local_ident end @qualified_name_cache[element] = result end |