public
Clone URL: git://github.com/vigetlabs/suggestive.git
Search Repo:
name age message
folder MIT-LICENSE Tue Aug 21 12:53:41 -0700 2007 suggestions plugin [ben]
folder README Tue Aug 28 05:27:15 -0700 2007 updated rdoc and readme [ben]
folder init.rb Tue Aug 21 12:53:41 -0700 2007 suggestions plugin [ben]
folder install.rb Tue Aug 21 12:53:41 -0700 2007 suggestions plugin [ben]
folder lib/ Tue Aug 28 05:27:15 -0700 2007 updated rdoc and readme [ben]
folder test/ Tue Aug 21 12:53:41 -0700 2007 suggestions plugin [ben]
README
Suggestive
==========

Suggestive is a plugin designed to help get valid data for your ActiveRecord models. To use it, you define a set of 
transformations to perform on your model to create valid values for an attribute. Then, when you call a 
dynamically-added method on an object, you will receive either the first available value those transformations produce, 
or nil if none of the pre-defined transformations generate a usable value.

Transformations must be passed as procs, though that allows everything from Proc.new {} and lambda {} to Symbol#to_proc 
declarations.

Example
=======

  class Person < ActiveRecord::Base
    suggestions_for :username, 
      Proc.new {|model| model.first_name}, 
      Proc.new {|model| model.last_name} #, etc.
  end

  person = Person.new :first_name => 'Bob', :last_name => 'Sully'
  username = person.suggest_username # => 'Bob', if it has not yet been saved as a username, else 'Sully' if it 
  available, else nil

To Do
=====

- Add scoping to the uniqueness check

Copyright (c) 2007 Ben Scofield, released under the MIT license