
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
A DSL for sorting active record results based on hash keys with the term sort in them.
gem 'all_sorts'
gem install all_sorts
All Sorts was originally developed to fill the need of being able to sort by one or multiple columns passed in the URL, however it works with ActiveRecord and basically takes in a hash. Included as a concern, this gem adds a ".sort" method to ActiveRecord which basically does some clever stuff by looking at the hash keys, creates a string by which to sort results, and calls ".order" with that string.
It also adds a ".sortable_fields" method for you to limit by which fields the records may be ordered.
Adds .sort, .sortable_fields methods to all of you models Somewhere in your apps bootstrap/startup code:
ActiveRecord::Base.include(AllSorts)
Adds .sort, .sortable_fields methods to only the User model
class User < ActiveRecord::Base
include AllSorts
end
In the model you can limit which fields are sortable. This is optional. If this isn't in your model, all fields are sortable.
class User < ActiveRecord::Base
sortable_fields :name, :salary
end
users = User.sort(params).all
#GIVEN THE DATA IN THE DB IS AS FOLLOWS:
adam:
id: 1
name: Adam
salary: 80000
bonus: true
dave1:
id: 2
name: Dave
salary: 9000
bonus: true
dave2:
id: 3
name: Dave
salary: 70000
bonus: true
admin:
id: 12
name: admin
salary: 10000
bonus: false
goofy:
id: 13
name: Goofy
salary: 11000
bonus: false
#THE CALL
users = User.sort({'sort_1_name' => 'asc', 'sort_2_salary' => 'desc'}).all
#RESULTS
[#<User id: 1, name: "Adam", salary: 80000, bonus: true, created_at: "2011-06-08 15:30:06", updated_at: "2011-06-08 15:30:06">,
#<User id: 3, name: "Dave", salary: 70000, bonus: true, created_at: "2011-06-08 15:30:06", updated_at: "2011-06-08 15:30:06">,
#<User id: 2, name: "Dave", salary: 9000, bonus: true, created_at: "2011-06-08 15:30:06", updated_at: "2011-06-08 15:30:06">,
#<User id: 13, name: "Goofy", salary: 11000, bonus: false, created_at: "2011-06-08 15:30:06", updated_at: "2011-06-08 15:30:06">,
#<User id: 12, name: "admin", salary: 10000, bonus: false, created_at: "2011-06-08 15:30:06", updated_at: "2011-06-08 15:30:06">]
FAQs
Unknown package
We found that all_sorts 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.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.