module Relix
  class PrimaryKeyIndex < Index
    include Ordering

    def watch
      name
    end

    def filter(r, object, value)
      !r.zscore(name, value)
    end

    def query(r, value)
      r.zcard(name)
    end

    def index(r, pk, object, value, old_value, rank)
      r.zadd(name, rank, pk)
    end

    def deindex(r, pk, object, old_value)
      r.zrem(name, pk)
    end

    def all(r, options={})
      r.zrange(name, *range_from_options(r, options))
    end

    def eq(r, value, options)
      [value]
    end

    def attribute_immutable?
      true
    end
  end
  register_index PrimaryKeyIndex
end
module Relix
  class PrimaryKeyIndex < Index
    include Ordering

    def initialize(set, base_name, accessor, options={})
      options[:immutable_attribute] = true unless options.has_key?(:immutable_attribute)
      super
    end

    def watch
      name
    end

    def filter(r, object, value)
      !r.zscore(name, value)
    end

    def query(r, value)
      r.zcard(name)
    end

    def index(r, pk, object, value, old_value, rank)
      r.zadd(name, rank, pk)
    end

    def deindex(r, pk, object, old_value)
      r.zrem(name, pk)
    end

    def all(r, options={})
      r.zrange(name, *range_from_options(r, options))
    end

    def eq(r, value, options)
      [value]
    end
  end
  register_index PrimaryKeyIndex
end

Refactor the primary key immutability to use the standard index option.
Refactor the primary key immutability to use the standard index option.

This allows you to override it an set `immutable_attribute: false`. I doubt that's ever very useful (or that you should do that) but hey, this is ruby: we give you the flexibility to shoot yourself in the foot.
