Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/spangenberg/alfred

Alfred provides better attr_accessor handling on your application.
https://github.com/spangenberg/alfred

Last synced: about 1 month ago
JSON representation

Alfred provides better attr_accessor handling on your application.

Awesome Lists containing this project

README

        

h1. Alfred - the unobtrusive butler who takes care of the uninvited guests "!https://secure.travis-ci.org/parcydo/alfred.png?branch=master!":http://travis-ci.org/parcydo/alfred

Alfred provides better attr_accessor handling on your application.

h2. Contact
* "Github":http://github.com/parcydo
* "Twitter":http://twitter.com/parcydo

h2. Documentation

* "Wiki":http://github.com/parcydo/alfred/wiki
* "YARD":http://rdoc.info/github/parcydo/alfred

h2. Preview

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

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

h2. Usage

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

h3. accessible and protected


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

h3. roles

Custom inherits from default role:


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

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

h3. events


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

h3. passwords

password_confirmation will automatically added by default.


class User < ActiveRecord::Base
alfred_accessible :password
end

h2. Requirements

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