Sha256: 7c0ce8f936d3432a3bc494c03d3b8436d677da4cba76ac98d229a0f9ff8101b5

Contents?: true

Size: 1.24 KB

Versions: 43

Compression:

Stored size: 1.24 KB

Contents

module ActiveGraph::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 ActiveGraph::InvalidPropertyOptionsError, "Can't set index on constrainted property #{name} (constraints get indexes automatically)" if constraint?(:unique)
        options[:index] = type
      end

      def constraint!(type = :unique)
        fail ActiveGraph::InvalidPropertyOptionsError, "Can't set constraint on indexed property #{name} (constraints get indexes automatically)" 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

43 entries across 43 versions & 1 rubygems

Version Path
activegraph-12.0.0.beta.5 lib/active_graph/shared/declared_property/index.rb
activegraph-12.0.0.beta.4 lib/active_graph/shared/declared_property/index.rb
activegraph-11.5.0.beta.3 lib/active_graph/shared/declared_property/index.rb
activegraph-12.0.0.beta.3 lib/active_graph/shared/declared_property/index.rb
activegraph-12.0.0.beta.2 lib/active_graph/shared/declared_property/index.rb
activegraph-11.5.0.beta.2 lib/active_graph/shared/declared_property/index.rb
activegraph-12.0.0.beta.1 lib/active_graph/shared/declared_property/index.rb
activegraph-11.5.0.beta.1 lib/active_graph/shared/declared_property/index.rb
activegraph-11.5.0.alpha.1 lib/active_graph/shared/declared_property/index.rb
activegraph-11.4.0 lib/active_graph/shared/declared_property/index.rb
activegraph-11.3.1 lib/active_graph/shared/declared_property/index.rb
activegraph-11.3.0 lib/active_graph/shared/declared_property/index.rb
activegraph-11.2.0 lib/active_graph/shared/declared_property/index.rb
activegraph-11.1.0 lib/active_graph/shared/declared_property/index.rb
activegraph-11.1.0.beta.1 lib/active_graph/shared/declared_property/index.rb
activegraph-11.1.0.alpha.4 lib/active_graph/shared/declared_property/index.rb
activegraph-11.1.0.alpha.3 lib/active_graph/shared/declared_property/index.rb
activegraph-11.1.0.alpha.2 lib/active_graph/shared/declared_property/index.rb
activegraph-11.1.0.alpha.1 lib/active_graph/shared/declared_property/index.rb
activegraph-10.2.0.beta.1 lib/active_graph/shared/declared_property/index.rb