Module: Shamu::Entities::EntityPath
- Included in:
- Auditing::Transaction
- Defined in:
- lib/shamu/entities/entity_path.rb
Overview
An entity path descrives 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.
Class 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.
Class 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.
29 30 31 32 33 34 35 36 |
# File 'lib/shamu/entities/entity_path.rb', line 29 def compose_entity_path( entities ) return unless entities.present? entities.each_with_object( "" ) do |entity, path| path << "/" if path.present? path << compose_single_entity( entity ) end end |
.decompose_entity_path(path) ⇒ Array<Array<String,String>>
Decompose an entity path into an array of arrays of entity classes with their ids.
52 53 54 55 56 57 58 59 60 |
# File 'lib/shamu/entities/entity_path.rb', line 52 def decompose_entity_path( path ) return unless path.present? path.split( "/" ).map do |node| entity, id = node.split "[" [ entity, id[ 0..-2 ] ] end end |