Auto_do_something is a project mainly written in Ruby, based on the MIT license.
A simple Ruby on Rails plugin to let model auto do something (like strip, downcase, etc.) before validation.
= auto_do_something
A simple Ruby on Rails plugin to let model auto do something (like strip, downcase, etc.) before validation.
== Usage
Before validation do strip, in your model:
auto :strip, :for => :field
For many fields:
auto :strip, :for => [:field1, :field2, ...]
Before validation do substr (with one argument):
auto :[], :with => 0...10, :for => :field_or_fields
Or if you want with more argument:
auto :[], :with => [0, 10], :for => :field_or_fields
=== In ActiveRecord
An example from spec:
class Item < ActiveRecord::Base auto :strip, :for => [:nickname, :email, :info] auto :downcase, :for => :email auto :[], :with => 0...10, :for => :info
auto :[], :with => [0, 10], :for => :info
end
user = User.new(:nickname => ' ayaya ', :email => ' [email protected] ', :info => ' hello world! ') user.valid? # or save
user.nickname.should == 'ayaya' user.email.should == '[email protected]' user.info.should == 'hello worl'
=== In ActiveModel
Just include AutoDoSomething in model class then use it like in ActiveRecord, see full example in spec/spec_helper.rb.
== Install
Gemfile:
gem 'auto_do_something', :git => 'git://github.com/ayamomiji/auto_do_something.git'
or install as a plugin:
rails plugin install git://github.com/ayamomiji/auto_do_something.git
== Contributing to auto_do_something
== Copyright
Copyright (c) 2011 ayaya. See LICENSE.txt for further details.