Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Sortify helps you handle user-provided sort options in Rails apps.
:warning: Warning:
Sortify is in the very early stages of development right now, has few tests and could introduce breaking changes. Use at your own risk.
To get started, add sortify to your gemfile:
gem 'sortify'
Then run bundle install
to fetch the current version.
Using Sortify is very simple. All you need to do is specify sorting options in your models, then call sortify
in your controllers naming a sorting option.
Sortify acts as a wrapper around ActiveRecord scopes, providing a tiny bit of extra functionality to keep track of valid sorting options.
If you don't know what scopes are, you can read about them here:
First you'll need to extend Sortify, and then you can specify your sort options.
class Item < ActiveRecord::Base
extend Sortify # includes the sortify methods in your model
default_sort_option :most_recent
sort_option :most_recent, -> { order(updated_at: :desc) }
sort_option :created_first, -> { order(created_at: :asc) }
end
sort_option
takes a symbol as a name, and a lambda, exactly like an ActiveRecord scope.
You can optionally provide a default_sort_option
which specifies which sort to use in the event that the user-specified sort is invalid or absent.
For your controllers, Sortify provides the sortify
method, which takes a string naming one of your sort options as an argument. Because Sortify uses scopes under the hood, it can be chained with other scopes.
:warning: Warning:
The
sortify
method will raise aNoMethodError
if it cannot find a sorting option with the name you passed in unless a valid default is specified.
class ItemController < ApplicationController
def index
@items = Item.sortify("most_recent") # sorts your items by most recent
@others = Item.sortify(params[:sort]) # sorts by the method specified in the params
end
end
Because it uses scopes under the hood, Sortify also provides separate methods for your sorting options:
class ItemController < ApplicationController
def index
@items = Item.created_first # all of your Items, sorted by creation date
end
end
Sortify is released under the MIT License
FAQs
Unknown package
We found that sortify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.