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

dstrelau-minty_scopes

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dstrelau-minty_scopes

  • 0.9.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

What

A collection of handy named_scopes that you should be able to use in just about any model.

Why

Named scopes turn ugly finders into pretty ones.

Howto

# environment.rb
config.gem 'dstrelau-minty_scopes', :source => "http://gems.github.com"

# any model
class Post < ActiveRecord::Base
  extend MintyScopes
end

Scopes

Scopes are grouped into modules by functionality. If you only want some scopes, feel free to extend only the modules you want: extend MintyScopes::Timestamps

Associations

with(:comments)       #=> :joins => :comments, :group => 'posts.id' (only posts with comments)
without(:comments)    #=> :joins => 'LEFT JOIN comments ON posts.id = comments.post_id', 
                      #   :conditions => {'comments.id' => nil}
including(:comments)  #=> :include => [:comments]

Except

except(post)              #=> [ 'posts.id NOT IN (?)', post ]
except(post, post)        #=> [ 'posts.id NOT IN (?)', [post, post] ]
except(post_collection)   #=> [ 'posts.id NOT IN (?)', post_collection ]

Order

newest      #=> { :order => 'created_at DESC', :limit => per_page || limit }
newest(20)  #=> { :order => 'created_at DESC', :limit => 20 }
oldest      #=> { :order => 'created_at ASC',  :limit => per_page || limit }
oldest(20)  #=> { :order => 'created_at ASC',  :limit => 20 }

Timestamps

created_on(date)  #=> :created_at => (date.beginning_of_day..date.end_of_day)
modified_on(date) #=> :modified_at => (date.beginning_of_day..date.end_of_day)

Thanks

Big thanks to Ryan Daigle for his utility_scopes plugin, the inspiration for this project.

License

© 2008 Dean Strelau, Mint Digital. All Rights Reserved.

FAQs

Package last updated on 11 Aug 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