Sha256: 738bc5484d12bebfe439b4f4faa550275dec0bbe43dbd95acb380f562bb79e3d

Contents?: true

Size: 1.87 KB

Versions: 72

Compression:

Stored size: 1.87 KB

Contents

module Neo4j
  module Schema
    class Operation
      attr_reader :label_name, :property, :options

      def initialize(label_name, property, options = default_options)
        @label_name = label_name.to_sym
        @property = property.to_sym
        @options = options
      end

      def self.incompatible_operation_classes
        []
      end

      def create!
        drop_incompatible!
        return if exist?
        label_object.send(:"create_#{type}", property, options)
      end

      def label_object
        @label_object ||= Neo4j::Label.create(label_name)
      end

      def incompatible_operation_classes
        self.class.incompatible_operation_classes
      end

      def drop!
        label_object.send(:"drop_#{type}", property, options)
      end

      def drop_incompatible!
        incompatible_operation_classes.each do |clazz|
          operation = clazz.new(label_name, property)
          operation.drop! if operation.exist?
        end
      end

      def exist?
        fail 'Abstract class, not implemented'
      end

      def default_options
        {}
      end

      def type
        fail 'Abstract class, not implemented'
      end
    end

    class ExactIndexOperation < Neo4j::Schema::Operation
      def self.incompatible_operation_classes
        [UniqueConstraintOperation]
      end

      def type
        'index'
      end

      def exist?
        label_object.indexes[:property_keys].include?([property])
      end
    end

    class UniqueConstraintOperation < Neo4j::Schema::Operation
      def self.incompatible_operation_classes
        [ExactIndexOperation]
      end

      def type
        'constraint'
      end

      def create!
        return if exist?
        super
      end

      def exist?
        Neo4j::Label.constraint?(label_name, property)
      end

      def default_options
        {type: :unique}
      end
    end
  end
end

Version data entries

72 entries across 72 versions & 2 rubygems

Version Path
neo4j-7.2.3 lib/neo4j/schema/operation.rb
neo4j-7.2.2 lib/neo4j/schema/operation.rb
neo4j-7.1.4 lib/neo4j/schema/operation.rb
neo4j-7.0.16 lib/neo4j/schema/operation.rb
neo4j-7.2.1 lib/neo4j/schema/operation.rb
neo4j_legacy-7.2.0.2 lib/neo4j/schema/operation.rb
neo4j_legacy-7.2.0.1 lib/neo4j/schema/operation.rb
neo4j-7.2.0 lib/neo4j/schema/operation.rb
neo4j-7.1.3 lib/neo4j/schema/operation.rb
neo4j-7.0.15 lib/neo4j/schema/operation.rb
neo4j-7.1.2 lib/neo4j/schema/operation.rb
neo4j-7.1.1 lib/neo4j/schema/operation.rb
neo4j-7.1.0 lib/neo4j/schema/operation.rb
neo4j-7.0.14 lib/neo4j/schema/operation.rb
neo4j-7.0.13 lib/neo4j/schema/operation.rb
neo4j-7.0.12 lib/neo4j/schema/operation.rb
neo4j-7.0.11 lib/neo4j/schema/operation.rb
neo4j-7.0.10 lib/neo4j/schema/operation.rb
neo4j-7.0.9 lib/neo4j/schema/operation.rb
neo4j-7.0.8 lib/neo4j/schema/operation.rb