= hashdown
http://github.com/rubysolo/hashdown
== DESCRIPTION:
hashdown is a super lightweight rails plugin that adds hash-style lookups and option lists (for generating dropdowns) to ActiveRecord models
== EXAMPLE:
Given the following class definition:
class State < ActiveRecord::Base
finder :abbreviation
selectable
end
You can look up states via their abbreviations like so:
@colorado = State[:CO]
These types of reference data models are often something you need to populate a select list on your form, so hashdown includes a handy method to generate your option list:
<%= form.select :state_id, State.select_options %>
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
def self.select_options
find(:all).map{|s| [s.name, s.id] }
end
end
...except it adds ActiveSupport caching for speedy lookups.
== Cache
By default caching is enabled. To disable it for select lists:
selectable :cache => false
== COMING SOON:
- configuration for key / value generation
== LICENSE:
(The MIT License)
Copyright © 2008-2009 Solomon White
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.