Repository is archived
No commit activity in last 3 years
No release in over 3 years
Allows to add a context to a named_scope that will be passed through the whole scope chain
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.11

Runtime

>= 2.0.0
 Project Readme

Context Aware Scope

An extension to ActiveRecord’s named scope

Usage

1. Add a context to a named_scope:

  named_scope :luxurious, :conditions => ['price > ?', 100], :context => {:price => 'luxurious'}
  named_scope :recent, :conditions => ['created_at > ?', 1.week.ago], :context => {:created_at => 'brand new'}

2. Execute the scopes:

  @products = Product.new.luxurious

3. And get the context:

  @products.context
  # => {:price => 'luxurious', :created_at => 'brand new'}
  "You are looking at #{@products.context.values.to_sentence} products"
  # => "You are looking at brand new and luxurious products"

Installation

Install the ContextAwareScope gem:

  gem install context_aware_scope

Compatibility
Only tested with ActiveRecord 2.3.8.
Rails 3 support planned.