Sha256: f55fa3a8e577e88d712406cabd057e9b3377c44667667e194d92488b2615b840

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

module Neo4j
  # Use this mixin to wrap Neo4j Relationship Java object.
  # This mixin is similar to Neo4j::NodeMixin which wraps Neo4j::Node Java objects.
  #
  # @example
  #   class Friend
  #      include Neo4j::RelationshipMixin
  #      property :since, :type => Fixnum, :index => :exact
  #      property :strength, :type => Float
  #      property :location
  #    end
  #
  #  Friend.new(:knows, node_a, node_b, :strength => 3.14)
  #  Friend.find(:strength => (2..5)).first
  #
  # = Class Method Modules
  # * {Neo4j::Wrapper::RelationshipMixin::ClassMethods}
  # * {Neo4j::Wrapper::Property::ClassMethods}
  # * {Neo4j::Core::Index::ClassMethods}
  # * {Neo4j::Wrapper::Find}
  module RelationshipMixin

    include Neo4j::Wrapper::RelationshipMixin::Initialize
    include Neo4j::Wrapper::RelationshipMixin::Delegates

    # @private
    def self.included(klass)
      klass.extend Neo4j::Wrapper::ClassMethods
      klass.extend Neo4j::Wrapper::RelationshipMixin::ClassMethods
      klass.extend Neo4j::Wrapper::Property::ClassMethods
      klass.extend Neo4j::Core::Index::ClassMethods
      klass.extend Neo4j::Wrapper::Find

      index_name = klass.to_s.gsub("::", '_')

      klass.rel_indexer do
        index_names :exact => "#{index_name}_exact", :fulltext => "#{index_name}_fulltext"
        trigger_on :_classname => klass.to_s
      end

      def klass.inherited(sub_klass)
        return super if sub_klass.to_s == self.to_s
        index_name = sub_klass.to_s.gsub("::", '_')
        base_class = self

        # make the base class trigger on the sub class nodes
        base_class._indexer.config.trigger_on :_classname => sub_klass.to_s

        sub_klass.rel_indexer do
          inherit_from base_class
          index_names :exact => "#{index_name}_exact", :fulltext => "#{index_name}_fulltext"
          trigger_on :_classname => sub_klass.to_s
        end
        super
      end

      super

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
neo4j-wrapper-0.0.1-java lib/neo4j/relationship_mixin.rb