Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A simple Ruby on Rails plugin to let model auto do something (like strip, downcase, etc.) before validation.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
Gemfile
Gemfile.lock
LICENSE.txt
README.rdoc
Rakefile
VERSION
auto_do_something.gemspec
init.rb

README.rdoc

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
  # or
  auto :[], :with => [0, 10], :for => :info
end

user = User.new(:nickname => ' ayaya ',
                :email => ' AYAYA@EXAMPLE.COM ',
                :info => ' hello world! ')
user.valid? # or save

user.nickname.should == 'ayaya'
user.email.should == 'ayaya@example.com'
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

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright © 2011 ayaya. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.