Sha256: 9b4ccdfc59728f54b4d4e92ca20894a8407082d57e1ca650faf86eaeff5e76ec

Contents?: true

Size: 793 Bytes

Versions: 1

Compression:

Stored size: 793 Bytes

Contents

module Neoon
  module Model
    module Schema

      def neo_index_list
        Neoon.db.list self.name
      end

      def neo_index_create keys = []
        Neoon.db.create self.name, keys
      end

      def neo_index_drop keys = []
        Neoon.db.drop self.name, keys
      end

      def neo_index_update
        cl = neo_index_list
        ck = neo_node_keys_to_index
        return cl if (cl) == (ck)

        neo_index_create(ck - cl) unless (ck - cl).empty?
        neo_index_drop(cl - ck) unless (cl - ck).empty?
        neo_index_list
      end

    private

      def neo_model_props
        self.neo_model_config.properties
      end

      def neo_node_keys_to_index
        neo_model_props.select{ |k, v| v[:index]==true }.keys.map(&:to_s).sort
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
neoon-0.0.3 lib/neoon/model/schema.rb