Module: SafetyCone::Filter

Defined in:
lib/safety_cone/filter.rb

Overview

Module for Filtering requests and raise notices and take measures

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Method to include to base class. This lets declare a before filter here



7
8
9
10
11
12
13
# File 'lib/safety_cone/filter.rb', line 7

def self.included(base)
  if Rails.version.to_i >= 5
    base.before_action :safety_cone_filter
  else
    base.before_filter :safety_cone_filter
  end
end

Instance Method Details

#safety_cone_filterObject

Filter method that does the SafetyCone action based on the configuration.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/safety_cone/filter.rb', line 17

def safety_cone_filter
  if cone = fetch_cone
    if cone.type == 'notice'
      flash.now["safetycone_#{notice_type(cone.type)}"] = cone.message
    else
      flash["safetycone_#{notice_type(cone.type)}"] = cone.message
    end

    redirect_to safety_redirect if cone.type == 'block'
  end
end