Sha256: efaeb1bbcee3d1a5776a233d09750c4c72abadc1238c8925100e0ea79251458f

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

class Neo4j::Node

  module Wrapper

    # this is a plugin in the neo4j-core so that the Ruby wrapper will be wrapped around the Neo4j::Node objects
    def wrapper
      wrappers = _class_wrappers
      if wrappers.empty?
        self
      else
        wrapper_classes = wrappers.map{|w| Neo4j::ActiveNode::Labels._wrapped_labels[w]}
        most_concrete_class = wrapper_classes.sort.first
        wrapped_node = most_concrete_class.new
        wrapped_node.init_on_load(self, self.props)
        wrapped_node
      end
    end

    def checked_labels_set
      @@_checked_labels_set ||= Set.new
    end

    def check_label(label_name)
      unless checked_labels_set.include?(label_name)
        load_class_from_label(label_name)
        # do this only once
        checked_labels_set.add(label_name)
      end
    end

    def load_class_from_label(label_name)
      begin
        label_name.to_s.split("::").inject(Kernel) {|container, name| container.const_get(name.to_s) }
      rescue NameError
        nil
      end
    end

    def _class_wrappers
      labels.find_all do |label_name|
        check_label(label_name)
        Neo4j::ActiveNode::Labels._wrapped_labels[label_name].class == Class
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
neo4j-3.0.0.alpha.8 lib/neo4j/wrapper.rb
neo4j-3.0.0.alpha.7 lib/neo4j/wrapper.rb