named_scope_for_time_attr

All information can be found here: nsfta.rubyforge.org/

DESCRIPTION:

Provides the ActiveRecord helper method named_scope_for_time_attr.

Given the name of a time attribute of an ActiveRecord model (e.g. created_at of Claim) it defines a correspondent named scope for easy access to an arbitrarily time range (scope).

FEATURES/PROBLEMS:

  • Defines a named scope for the given time attribute

  • Allows easy access to an arbitrarily time range

  • Defines a named scope order for easy ordering of the result

SYNOPSIS:

Define the named scope created_at and last_modified_on via named_scope_for_time_attr:

class Claim < ActiveRecord::Base
  named_scope_for_time_attr :created_at, :order => 'created_at DESC'
  named_scope_for_time_attr :last_modified_on, :limit => 10
  ...
end

It is then possible to use the scope method created_at and updated_at as follows:

Claim.created_at(2.days.ago)
Claim.created_at(2.days.ago, 1.days.ago)
Claim.created_at(:today)
Claim.created_at(:this_month).order('created_at DESC')
Claim.created_at(:q1) # quarter one
Claim.last_modified_on(3.weeks.ago, :limit => 20)
...

See API doc for class named_scope_for_time_attr for examples:

REQUIREMENTS:

  • ActiveRecord

INSTALL:

  • sudo gem install named_scope_for_time_attr

LICENSE:

(The MIT License)

Copyright © 2009-* Thomas Baustert

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.