Navigation Menu

Skip to content

coryodaniel/within_named_scope

Repository files navigation

Within Named Scope

A simple gem for drying up checking if an ActiveRecord instance is within a named scope.

Support for Rails 3.2+ and 4.0+

Usage

Using the 'in_scope?' method:

class Post < ActiveRecord::Base
  scope :published, -> { where(published: true)}
end

Post.first.in_scope? :published

Adding a named method:

class Post < ActiveRecord::Base
  scope :published, -> { where(published: true)}
  
  # Would default to published?
  scope_membership :published, as: :is_published?
end

Post.first.is_published?

Authors

  • Cory ODaniel

About

Determine if an activerecord instance is within a named scope.

Resources

License

Stars

Watchers

Forks

Packages

No packages published