Module: DarDaDa::ActionControllerExtension::ClassMethods

Defined in:
lib/dar_da_da/action_controller_extension.rb

Instance Method Summary collapse

Instance Method Details

#define_access_control(user_class, user_method_name = :current_user) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dar_da_da/action_controller_extension.rb', line 11

def define_access_control(user_class, user_method_name = :current_user)
  user_class.dar_dar_da.all_rights.each do |right|
    self.class_eval("
      private

      def check_if_#{user_class.name.downcase}_is_allowed_to_#{right}
        raise ActionController::ForbiddenError.new unless #{user_method_name}.allowed_to_#{right}?
      end
    ")

    self.class_eval("
      def self.require_right(right, options={})
        before_action :\"check_if_#{user_class.name.downcase}_is_allowed_to_#\{right}\", options
      end
    ")
  end
end