Project

alfred

0.0
No commit activity in last 3 years
No release in over 3 years
Alfred provides better attr_accessor handling on your application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.1.0
 Project Readme

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).