Module: Neo4j::RelWrapping

Defined in:
lib/neo4j/active_rel/rel_wrapper.rb

Class Method Summary collapse

Class Method Details

.class_from_type(rel_type) ⇒ Object



26
27
28
# File 'lib/neo4j/active_rel/rel_wrapper.rb', line 26

def class_from_type(rel_type)
  Neo4j::ActiveRel::Types::WRAPPED_CLASSES[rel_type] || Neo4j::ActiveRel::Types::WRAPPED_CLASSES[rel_type] = rel_type.to_s.camelize
end

.wrapper(rel) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/neo4j/active_rel/rel_wrapper.rb', line 11

def wrapper(rel)
  rel.props.symbolize_keys!
  begin
    most_concrete_class = class_from_type(rel.rel_type).constantize
    return rel unless most_concrete_class < Neo4j::ActiveRel
    most_concrete_class.new
  rescue NameError => e
    raise e unless e.message =~ /(uninitialized|wrong) constant/

    return rel
  end.tap do |wrapped_rel|
    wrapped_rel.init_on_load(rel, rel.start_node_id, rel.end_node_id, rel.type)
  end
end