github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

mbleigh / fetches

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 29
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

A Rails plugin to simplify the fetching and memoization of records for parameter-based finds. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Bumping gem version to see if GitHub will build it now. 
mbleigh (author)
Wed Jan 14 11:02:21 -0800 2009
commit  f0d51e15ac0d3d313309c42b89f70d548e219ea5
tree    6f0792bc8abb672150b45ef5f271721ae03afb56
parent  2538ef18936047294b7d22543fa05d6c1c03934f
fetches /
name age
history
message
file .gitignore Loading commit data...
file MIT-LICENSE
file README
file Rakefile
file fetches.gemspec
file init.rb
directory lib/
directory rails/
directory test/
README
= Fetches

Fetches is a simple extension to ActionController that allows you to DRY up your
model fetching with a simple, intuitive syntax. Rather than creating helpers or
manually finding records each time an action is processed, simply add a call to
'fetches' in your controller and it will take care of the rest.

== Installation

Fetches is available as a gem as well as in traditional plugin format. To install
as a gem, add this to your environment.rb:

  config.gem 'mbleigh-fetches', :source => 'http://gems.github.com', :lib => "fetches"
  
To install it as a traditional plugin:

  script/plugin install git://github.com/mbleigh/fetches.git

== Example

  class UsersController < ApplicationController
    fetches :user
    
    def show
      user # equivalent to a memoizing call to User.find(params[:id])
    end
  end
  
It's very simple, and can also be extended to meet more complex demands, such as:
  
  # routes as a nested /users/:user_id/articles
  class ArticlesController < ApplicationController
    fetches :user, :as => :author, :from => :user_id, :using => :find_by_login
    fetches :article
    
    def index
      author # equivalent to User.find_by_login(params[:user_id])
    end
  end
  
You may also pass a Proc into the "from" option in order to fetch from
a more complex set of requirements:

  class UsersController < ApplicationController
    fetches :user, :from => Proc.new{ |c| c.params[:user_id] || c.params[:id] }
  end
  
Finally, you can use the :initialize option to initialize a new record using
parameters or Proc-based information:

  fetches :user, :initialize => true
  fetches :user, :initialize => :author # initialize from params[:author]
  fetches :user, :initialize => Proc.new{ |c| {:login => params[:login], :email => params[:email]} }

The helper method generated memoizes (initializes once then doesn't make additional
calls to the database) and is available both in the controller and the view.

Copyright (c) 2008 Michael Bleigh and Intridea, Inc., released under the MIT license
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server