spangenberg / alfred

Alfred provides better attr_accessor handling on your application.

Home Page:http://rubygems.org/gems/alfred

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alfred – the unobtrusive butler who takes care of the uninvited guests

Alfred provides better attr_accessor handling on your application.

Contact

Documentation

Preview

Without Alfred, and with much mess:

# app/models/user.rb
class User < ActiveRecord::Base
  attr_accessible :email, :password, :password_confirmation
  attr_accessible :email, :password, :password_confirmation, :username, as: :admin
  attr_accessible :email, :password, :password_confirmation, :username, as: :on_create
end

Have to use a special role:

# app/controllers/users_controlelr.rb
class UsersController < ApplicationController
  def create
    @user = User.create(params[:user], as: :on_create)
  end
end

With Alfred and no hassles:

# app/models/user.rb
class User < ActiveRecord::Base
  alfred_accessible :email, :password
  alfred_accessible :username, as: :admin
  alfred_accessible :username, on: :create
end

Nothing special here:

# app/controllers/users_controlelr.rb
class UsersController < ApplicationController
  def create
    @user = User.create(params[:user])
  end
end

Usage

alfred_accessible and alfred_protected behaves just like attr_accessible and attr_protected on steroids.

accessible and protected

  class User < ActiveRecord::Base
    alfred_accessible :a, :b
    alfred_protected :c, :d
  end

roles

Custom inherits from default role:

  class User < ActiveRecord::Base
    alfred_accessible :a, :b
    alfred_accessible :c, :d, as: :custom
  end

custom inheritance

  class User < ActiveRecord::Base
    alfred_accessible :a, :b
    alfred_accessible :c, :d, as: :custom
    alfred_accessible :e, :f, as: :custom2, inherit: :custom
  end

events

  class User < ActiveRecord::Base
    alfred_accessible :a, :b
    alfred_accessible :c, :d, on: :create
    alfred_accessible :e, :f, on: :update
  end

passwords

password_confirmation will automatically added by default.

  class User < ActiveRecord::Base
    alfred_accessible :password
  end

Requirements

  • Ruby 1.9.2 (Ruby 1.9.1 is not supported).
  • Rails 3.1.x (Rails 3.0.x is not supported).

About

Alfred provides better attr_accessor handling on your application.

http://rubygems.org/gems/alfred


Languages

Language:Ruby 100.0%