Sha256: 0f18a47656b30e667af441df11b6ff0138e5bcbaea381adb8c4291cd4bf4da5e

Contents?: true

Size: 1.16 KB

Versions: 50

Compression:

Stored size: 1.16 KB

Contents

module Neo4j::Shared
  class DeclaredProperty
    # None of these methods interact with the database. They only keep track of property settings in models.
    # It could (should?) handle the actual indexing/constraining, but that's TBD.
    module Index
      def index_or_constraint?
        index?(:exact) || constraint?(:unique)
      end

      def index?(type = :exact)
        options.key?(:index) && options[:index] == type
      end

      def constraint?(type = :unique)
        options.key?(:constraint) && options[:constraint] == type
      end

      def index!(type = :exact)
        fail Neo4j::InvalidPropertyOptionsError, "Unable to set index on constrainted property #{name}" if constraint?(:unique)
        options[:index] = type
      end

      def constraint!(type = :unique)
        fail Neo4j::InvalidPropertyOptionsError, "Unable to set constraint on indexed property #{name}" if index?(:exact)
        options[:constraint] = type
      end

      def unindex!(type = :exact)
        options.delete(:index) if index?(type)
      end

      def unconstraint!(type = :unique)
        options.delete(:constraint) if constraint?(type)
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
neo4j-6.1.12 lib/neo4j/shared/declared_property/index.rb
neo4j-6.0.9 lib/neo4j/shared/declared_property/index.rb
neo4j-6.1.11 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.5 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.4 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.3 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.2 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.1 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.0 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.0.rc.7 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.0.rc.6 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.0.rc.5 lib/neo4j/shared/declared_property/index.rb
neo4j-6.1.10 lib/neo4j/shared/declared_property/index.rb
neo4j-6.0.8 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.0.rc.4 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.0.rc.3 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.0.rc.2 lib/neo4j/shared/declared_property/index.rb
neo4j-6.1.9 lib/neo4j/shared/declared_property/index.rb
neo4j-6.0.7 lib/neo4j/shared/declared_property/index.rb
neo4j-7.0.0.rc.1 lib/neo4j/shared/declared_property/index.rb