Module: ActiveGraph::Relationship::Wrapping

Defined in:
lib/active_graph/relationship/wrapping.rb

Class Method Summary collapse

Class Method Details

.class_from_type(type) ⇒ Object



20
21
22
# File 'lib/active_graph/relationship/wrapping.rb', line 20

def class_from_type(type)
  ActiveGraph::Relationship::Types::WRAPPED_CLASSES[type] || ActiveGraph::Relationship::Types::WRAPPED_CLASSES[type] = type.to_s.downcase.camelize
end

.wrapper(rel) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_graph/relationship/wrapping.rb', line 5

def wrapper(rel)
  rel.properties.symbolize_keys!
  begin
    most_concrete_class = class_from_type(rel.type).constantize
    return rel unless most_concrete_class < ActiveGraph::Relationship
    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