Class: Hello::RailsController::RestrictByRole

Inherits:
Object
  • Object
show all
Defined in:
lib/hello/rails_controller/restrict_by_role.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ RestrictByRole

Returns a new instance of RestrictByRole.



5
6
7
# File 'lib/hello/rails_controller/restrict_by_role.rb', line 5

def initialize(controller)
  @controller = controller
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



69
70
71
72
73
74
75
# File 'lib/hello/rails_controller/restrict_by_role.rb', line 69

def method_missing(method, *args, &block)
  if @controller.respond_to?(method)
    @controller.send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#dont_kick(*roles) ⇒ Object



13
14
15
# File 'lib/hello/rails_controller/restrict_by_role.rb', line 13

def dont_kick(*roles)
  to_home_page if not current_user.in_any_role?(roles)
end

#kick(*roles) ⇒ Object



9
10
11
# File 'lib/hello/rails_controller/restrict_by_role.rb', line 9

def kick(*roles)
  to_home_page if current_user.in_any_role?(roles)
end