Module: Annex::Config

Defined in:
lib/annex/config.rb

Constant Summary collapse

DEFAULT_AUTHENTICATION =

Annex is setup to try and authenticate with warden If warden is found, then it will try to authenticate

This is valid for custom warden setups, and also devise If you’re using the admin setup for devise, you should set Annex to use the admin

Proc.new do
  request.env['warden'].try(:authenticate!)
end
DEFAULT_AUTHORIZE =
Proc.new {}
DEFAULT_CURRENT_USER =
Proc.new do
  request.env["warden"].try(:user) || respond_to?(:current_user) && current_user
end

Class Method Summary collapse

Class Method Details

.authenticate_with(&blk) ⇒ Object

Setup authentication to be run as a before filter This is run inside the controller instance so you can setup any authentication you need to

By default, the authentication will run via warden if available and will run the default.

If you use devise, this will authenticate the same as authenticate_user!

Examples:

Devise admin

Annex.config do |config|
  config.authenticate_with do
    authenticate_admin!
  end
end

Custom Warden

Annex.config do |config|
  config.authenticate_with do
    warden.authenticate! :scope => :paranoid
  end
end

See Also:



47
48
49
50
# File 'lib/annex/config.rb', line 47

def authenticate_with(&blk)
  @authenticate = blk if blk
  @authenticate || DEFAULT_AUTHENTICATION
end

.authorize_with(*args, &block) ⇒ Object

Setup authorization to be run as a before filter This is run inside the controller instance so you can setup any authorization you need to.

By default, there is no authorization.

To use an authorization adapter, pass the name of the adapter. For example, to use with CanCan, pass it like this.

Examples:

Custom

Annex.config do |config|
  config.authorize_with do
    redirect_to root_path unless warden.user.is_admin?
  end
end

CanCan

Annex.config do |config|
  config.authorize_with :cancan
end

See Also:



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/annex/config.rb', line 73

def authorize_with(*args, &block)
  extension = args.shift
  if(extension)
    @authorize = Proc.new {
      @authorization_adapter = Annex::AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact)
    }
  else
    @authorize = block if block
  end
  @authorize || DEFAULT_AUTHORIZE
end

.connect_with(adapter = :activerecord) ⇒ Object



85
86
87
# File 'lib/annex/config.rb', line 85

def connect_with(adapter = :activerecord)
  @adapter = adapter
end