Sha256: 510f743430ec5189e4367a32d955a46b2c0896d397eea3ba6560060baac458b1

Contents?: true

Size: 1.7 KB

Versions: 20

Compression:

Stored size: 1.7 KB

Contents

module Neo4j
  # Makes Neo4j Relationships more or less act like ActiveRecord objects.
  # See documentation at https://github.com/neo4jrb/neo4j/wiki/Neo4j%3A%3AActiveRel
  module ActiveRel
    extend ActiveSupport::Concern

    include Neo4j::Shared
    include Neo4j::ActiveRel::Initialize
    include Neo4j::Shared::Identity
    include Neo4j::Shared::SerializedProperties
    include Neo4j::ActiveRel::Property
    include Neo4j::ActiveRel::Persistence
    include Neo4j::ActiveRel::Validations
    include Neo4j::ActiveRel::Callbacks
    include Neo4j::ActiveRel::Query
    include Neo4j::ActiveRel::Types

    class FrozenRelError < StandardError; end

    def initialize(*args)
      load_nodes
      super
    end

    def inspect
      attribute_pairs = attributes.sort.map { |key, value| "#{key}: #{value.inspect}" }
      attribute_descriptions = attribute_pairs.join(', ')
      separator = ' ' unless attribute_descriptions.empty?

      cypher_representation = "#{node_cypher_representation(from_node)}-[:#{type}]->#{node_cypher_representation(to_node)}"
      "#<#{self.class.name} #{cypher_representation}#{separator}#{attribute_descriptions}>"
    end

    def node_cypher_representation(node)
      node_class = node.class
      id_name = node_class.id_property_name
      labels = ':' + node_class.mapped_label_names.join(':')

      "(#{labels} {#{id_name}: #{node.id.inspect}})"
    end

    def neo4j_obj
      _persisted_obj || fail('Tried to access native neo4j object on a non persisted object')
    end

    included do
      include Neo4j::Timestamps if Neo4j::Config[:record_timestamps]

      def self.inherited(other)
        super
      end
    end

    ActiveSupport.run_load_hooks(:active_rel, self)
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
neo4j-6.0.0.alpha.9 lib/neo4j/active_rel.rb
neo4j-5.2.13 lib/neo4j/active_rel.rb
neo4j-5.2.12 lib/neo4j/active_rel.rb
neo4j-6.0.0.alpha.8 lib/neo4j/active_rel.rb
neo4j-6.0.0.alpha.7 lib/neo4j/active_rel.rb
neo4j-5.2.11 lib/neo4j/active_rel.rb
neo4j-6.0.0.alpha.5 lib/neo4j/active_rel.rb
neo4j-6.0.0.alpha.4 lib/neo4j/active_rel.rb
neo4j-5.2.10 lib/neo4j/active_rel.rb
neo4j-6.0.0.alpha.3 lib/neo4j/active_rel.rb
neo4j-6.0.0.alpha.2 lib/neo4j/active_rel.rb
neo4j-6.0.0.alpha.1 lib/neo4j/active_rel.rb
neo4j-5.2.9 lib/neo4j/active_rel.rb
neo4j-5.2.8 lib/neo4j/active_rel.rb
neo4j-5.2.7 lib/neo4j/active_rel.rb
neo4j-5.2.6 lib/neo4j/active_rel.rb
neo4j-5.2.5 lib/neo4j/active_rel.rb
neo4j-5.2.3 lib/neo4j/active_rel.rb
neo4j-5.2.2 lib/neo4j/active_rel.rb
neo4j-5.2.1 lib/neo4j/active_rel.rb