public
Description: super lightweight rails plugin that adds hash-style lookups and option lists (for generating dropdowns) to ActiveRecord models
Homepage:
Clone URL: git://github.com/rubysolo/hashdown.git
name age message
file README.rdoc Sun Aug 09 15:28:23 -0700 2009 model level configuration implmented - update T... [rubysolo]
file Rakefile Tue Sep 29 06:12:45 -0700 2009 add tests, implement cache key depends on curre... [rubysolo]
file init.rb Thu May 28 07:25:44 -0700 2009 rename to hashdown. add selectacble example to... [rubysolo]
directory lib/ Sat Oct 10 22:18:15 -0700 2009 add grouped select options [rubysolo]
directory test/ Sat Oct 10 22:18:15 -0700 2009 add grouped select options [rubysolo]
README.rdoc

hashdown

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.

COMING SOON:

  • configuration for key / value generation
    • app level

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.