Module: Shamu::Entities::EntityPath
- Extended by:
- EntityPath
- Included in:
- Auditing::Transaction, EntityPath
- Defined in:
- lib/shamu/entities/entity_path.rb
Overview
An entity path describes one or more levels of parent/child relationships that can be used to navigate from the root entity to a target entity.
Entity paths can be used to identify polymorphic relationships between entities managed by difference services.
Instance Method Summary collapse
-
#compose_entity_path(entities) ⇒ String
Composes an array of entities describing the path from the root entity to the leaf into a string.
-
#decompose_entity_path(path) ⇒ Array<Array<String,String>>
Decompose an entity path into an array of arrays of entity classes with their ids.
Instance Method Details
#compose_entity_path(entities) ⇒ String
Composes an array of entities describing the path from the root entity to the leaf into a string.
28 29 30 31 32 33 34 |
# File 'lib/shamu/entities/entity_path.rb', line 28 def compose_entity_path( entities ) return unless entities.present? entities.map do |entity| compose_single_entity( entity ) end.join( "/" ) end |
#decompose_entity_path(path) ⇒ Array<Array<String,String>>
Decompose an entity path into an array of arrays of entity classes with their ids.
49 50 51 52 53 54 55 56 57 |
# File 'lib/shamu/entities/entity_path.rb', line 49 def decompose_entity_path( path ) return unless path.present? path.split( "/" ).map do |node| entity, id = node.split "[" [ entity, id[ 0..-2 ] ] end end |