Class: Graphiti::ActiveGraph::Scoping::Internal::PathDescriptor

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#attributeObject

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

#pathObject

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

#relObject

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

#scopeObject

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_propertyObject



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

Raises:

  • (Exception)


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

Returns:

  • (Boolean)


17
18
19
# File 'lib/graphiti/active_graph/scoping/internal/path_descriptor.rb', line 17

def next?
  @has_next
end

#path_relationshipsObject



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