Class: Graphiti::ActiveGraph::Scoping::Internal::PathDescriptor
- Inherits:
-
Object
- Object
- Graphiti::ActiveGraph::Scoping::Internal::PathDescriptor
- Defined in:
- lib/graphiti/active_graph/scoping/internal/path_descriptor.rb
Overview
Determine valid paths specified in filter and sort API params and normalize them for neo4j
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#rel ⇒ Object
readonly
Returns the value of attribute rel.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
- #declared_property ⇒ Object
- #increment(key) ⇒ Object
-
#initialize(scope, rel) ⇒ PathDescriptor
constructor
A new instance of PathDescriptor.
- #next? ⇒ Boolean
- #path_relationships ⇒ Object
Constructor Details
#initialize(scope, rel) ⇒ PathDescriptor
Returns a new instance of PathDescriptor.
9 10 11 12 13 14 15 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 9 def initialize(scope, rel) self.scope = scope self.path = [] self.attribute = :id self.rel = rel @has_next = true end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
6 7 8 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 6 def attribute @attribute end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 6 def path @path end |
#rel ⇒ Object
Returns the value of attribute rel.
6 7 8 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 6 def rel @rel end |
#scope ⇒ Object
Returns the value of attribute scope.
6 7 8 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 6 def scope @scope end |
Class Method Details
.association_for_relationship(associations, key) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 40 def self.association_for_relationship(associations, key) key_class_name = key[:rel_name].classify key_assoc_name = key[:rel_name].gsub('_rel', '') assocs = associations.find_all { |_, value| value.relationship_class_name == key_class_name || value.name.to_s == key_assoc_name } assocs.size == 1 ? assocs.first : nil end |
.parse(scope, path, rel = nil) ⇒ Object
34 35 36 37 38 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 34 def self.parse(scope, path, rel = nil) path_desc = new(scope, rel) path_desc.increment(path.shift) while path_desc.next? && path.present? path_desc if path.empty? end |
Instance Method Details
#declared_property ⇒ Object
30 31 32 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 30 def declared_property (relationship_class || scope).attributes[attribute] end |
#increment(key) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 21 def increment(key) raise Exception, 'no continuation on path possible' unless next? if rel increment_from_cache(key) else increment_from_scope(key) end end |
#next? ⇒ Boolean
17 18 19 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 17 def next? @has_next end |
#path_relationships ⇒ Object
47 48 49 |
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 47 def path_relationships path.map { |elm| elm[:rel_name].to_sym } end |