forked from rubysolo/hashdown
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
= finder | ||
|
||
http://github.com/rubysolo/finder | ||
|
||
== DESCRIPTION: | ||
|
||
finder is a super light rails plugin that adds hash-style lookups to ActiveRecord models | ||
|
||
== EXAMPLE: | ||
|
||
Given the following class definition: | ||
|
||
class State < ActiveRecord::Base | ||
finder :abbreviation | ||
end | ||
|
||
You can look up states via their abbreviations like so: | ||
|
||
@colorado = State[:co] | ||
|
||
This is roughly equivalent to the following implementation: | ||
|
||
class State < ActiveRecord::Base | ||
validates_uniqueness_of :abbreviation | ||
|
||
def self.[](state_code) | ||
find_by_abbreviation(state_code) | ||
end | ||
end | ||
|
||
...except it adds ActiveSupport caching for speedy lookups. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'finder' | ||
ActiveRecord::Base.class_eval do | ||
include ActiveRecord::Finder | ||
include Rubysolo::Finder | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters