Class: Clearance::Constraints::SignedIn

Inherits:
Object
  • Object
show all
Defined in:
lib/clearance/constraints/signed_in.rb

Overview

Can be applied to make a set of routes visible only to users that are signed in.

# config/routes.rb
constraints Clearance::Constraints::SignedIn.new do
  resources :posts
end

In the example above, requests to /posts from users that are not signed in will result in a 404. You can make additional assertions about the user by passing a block. For instance, if you want to require that the signed-in user be an admin:

# config/routes.rb
constraints Clearance::Constraints::SignedIn.new { |user| user.admin? } do
  resources :posts
end

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ SignedIn

Returns a new instance of SignedIn



21
22
23
# File 'lib/clearance/constraints/signed_in.rb', line 21

def initialize(&block)
  @block = block || lambda { |user| true }
end

Instance Method Details

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/clearance/constraints/signed_in.rb', line 25

def matches?(request)
  @request = request
  signed_in? && current_user_fulfills_additional_requirements?
end