lib/risky/secondary_indexes.rb
def index2i(name, opts = {})
      name = name.to_s

      opts.replace({:type => :int, :multi => false, :finder => :find}.merge(opts))
      indexes2i[name] = opts

      class_eval %Q{
        def #{name}
          @indexes2i['#{name}']
        end

        def #{name}=(value)
          @indexes2i['#{name}'] = value
        end
      }

      if opts[:map]
        if opts[:map] === true # assume that it ends in _id
          model_name = name[0..-4]
          map_model(model_name, opts)
        else
          model_name = name[0..-(opts[:map].length + 1)]
          map_model(model_name, opts.merge(:suffix => opts[:map]))
        end
      end
    end
def index2i(name, opts = {})
      name = name.to_s

      opts.replace({:type => :int, :multi => false, :finder => :find}.merge(opts))
      indexes2i[name] = opts

      class_eval %Q{
        def #{name}
          @indexes2i['#{name}']
        end

        def #{name}=(value)
          @indexes2i['#{name}'] = value
        end
      }

      if opts[:map]
        if opts[:map] === true # assume that it ends in _id
          model_name = name[0..-4]
          map_model(model_name, opts)
        else
          model_name = name[0..-(opts[:map].length + 1)]
          map_model(model_name, opts.merge(:suffix => opts[:map]))
        end
      end
    end
Add a new secondary index to this model.
 Default option is :type => :int, can also be :bin
 Default option is :multi => false, can also be true
 Option :map can be used to map the index to a model (see map_model).
   This assumes by default that the index name ends in _id (use :map => true)
   If it ends in something else, use :map => '_suffix'