0.0
No commit activity in last 3 years
No release in over 3 years
controller module for extracting datetime range from request params
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Timeframeable

Timeframeable module allows you to easily extract datetime range from request params keeping you controllers DRY. Intended to use with Rails 3, but may be compatible or easily adaptable with/to other versions.

Travis CI

Installation

Add this line to your application's Gemfile:

gem 'timeframeable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install timeframeable

Usage

Controller module

Typical usage:

class FrontController < ApplicationController
  include Timeframeable::Controller
  timeframeable

This will inject dates from params[:start] and params[:end] into @timeframe.start and @timeframe.end. nil will be used if parameter was not found. You can specify default values to avoid this:

  timeframeable :defaults => [:beginning_of_month, :now]

You can specify keys to seek at params hash:

  timeframeable :defaults => [:beginning_of_month, :now],
    :start_key => :s,
    :end_key   => :e

Or even specify instance variable to fill:

  timeframeable :defaults => [:beginning_of_month, :now],
    :start_key => :s,
    :end_key   => :e,
    :variable  => :tf

ActiveRecord module

class Model < ActiveRecord::Base
  include Timeframeable::Scope
end

Model.timeframe(:created_at, @timeframe).count

TODO

It might be usefull to add :start_value and :end_value lambda options, which will extract appropriate values from params bypassing :start_key and :end_key.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request