Module: SqAuth::SqAuthHelpers::ActionController::ClassMethods

Includes:
DSL, RailsDSL
Defined in:
lib/sq_auth/sq_auth_helpers/sq_auth_helpers_rails.rb

Instance Method Summary collapse

Methods included from RailsDSL

#access_action_except, #access_actions_except, #method_missing

Methods included from DSL

#access_action, #access_actions, #draw_for, #sq_auth_access

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SqAuth::SqAuthHelpers::RailsDSL

Instance Method Details

#create_filter(roles, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sq_auth/sq_auth_helpers/sq_auth_helpers_rails.rb', line 11

def create_filter roles, options = {}
  filter_options = {}
  filter_options[:only] = @sq_auth_actions_only
  filter_options[:except] = @sq_auth_actions_except
  before_filter(filter_options) do |controller|
    format_type = options[:format_type]
    format_condition = (format_type == "all") || (format_type.nil?) || (controller.request.format.send("#{format_type}?".to_sym))
    if format_condition
      error_proc = nil
      api_options = {}
      if format_type == "json"
        error_proc = Proc.new do |message|
          render json: message
        end
        api_options[:draw] = false
      else
        error_proc = Proc.new do |message|
          render text: message
        end
        api_options[:draw] = true
      end
      SqAuth.api_filter(roles, Proc.new {}, error_proc, api_options)
    end
  end
end