Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ohm-sorted

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ohm-sorted

  • 0.4.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ohm-sorted

Gem Version Build Status Code Climate

Sorted indices for Ohm

Setup

  1. Include the Callbacks and Sorted modules in your model:

     include Ohm::Callbacks 
     include Ohm::Sorted
    
  2. Add the sorted indices you want to your model:

  • If you want a complete index:

    sorted :created_at
    
  • If you want to partition the index based on an attribute:

    sorted :created_at, :group_by => :site_id
    

You can use both indices for the same attribute, as the partition keys are namespaced by the group_by attribute.

You will need to resave every model if they already exist for the index to get built.

The ranking attribute must be of a type that responds to to_f.

Usage

To query the sorted index, use the sorted_find class method.

>> Post.sorted_find(:created_at, site_id: "ar")

This returns an Ohm::SortedSet, similiar to an Ohm::Set but backed by a sorted set.

To limit the results to a certain score range, use the between method. This and the following methods return a new copy of the set object, but data is not read until it is necessary.

>> Post.sorted_find(:created_at, site_id: "ar").between(start_time, end_time)

To take a slice of the results, use the slice method. This returns a new copy of the set which will pass its offset and count parameters to Redis.

>> Post.sorted_find(:created_at, site_id: "ar").slice(2, 4)

Requirements

This plugin works with Ohm versions higher than 0.1.3.

Acknowledgements

Many thanks to Damian Janowski (https://github.com/djanowski)

FAQs

Package last updated on 28 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc