Module: Mistiq
- Defined in:
- lib/mistiq/base.rb,
lib/mistiq/init.rb,
lib/mistiq/defaults.rb,
lib/mistiq/middleware.rb
Defined Under Namespace
Classes: Middleware, Railtie, RouteWrapper, RoutesInspector
Instance Method Summary collapse
-
#disable_action_ops(action, strip_links = true) ⇒ Object
disable all ‘action’ operations across the rails application.
-
#disable_controller(controller, strip_links = true) ⇒ Object
disable all actions for a specific controller.
-
#disable_create_ops(strip_links = true) ⇒ Object
disable all create operations across the rails application.
-
#disable_destroy_ops(strip_links = true) ⇒ Object
disable all destroy operations across the rails application.
-
#disable_update_ops(strip_links = true) ⇒ Object
disable all edit operations across the rails application.
- #initialize ⇒ Object
-
#set_guard_on ⇒ Object
checks every time the application runs whether any of the rules is true and applies the specified action.
-
#set_guard_rule(condition, consequence, strip_links = true) ⇒ Object
add a new rule to look out for.
Instance Method Details
#disable_action_ops(action, strip_links = true) ⇒ Object
disable all ‘action’ operations across the rails application
12 13 14 15 16 17 |
# File 'lib/mistiq/defaults.rb', line 12 def disable_action_ops(action,strip_links=true) Railtie.get_regex_hash.each { |r,p| set_guard_rule(true,r,strip_links) if r.match(/.*#{action}/) } end |
#disable_controller(controller, strip_links = true) ⇒ Object
disable all actions for a specific controller
3 4 5 6 7 8 |
# File 'lib/mistiq/defaults.rb', line 3 def disable_controller(controller,strip_links=true) Railtie.get_regex_hash.each { |r,p| set_guard_rule(true,r,strip_links) if r.match(/#{controller}.*/) } end |
#disable_create_ops(strip_links = true) ⇒ Object
disable all create operations across the rails application
21 22 23 24 25 26 |
# File 'lib/mistiq/defaults.rb', line 21 def disable_create_ops(strip_links=true) Railtie.get_regex_hash.each { |r,p| set_guard_rule(true,r,strip_links) if r.match(/.*#new/) || r.match(/.*#add/) || r.match(/.*#create/) } end |
#disable_destroy_ops(strip_links = true) ⇒ Object
disable all destroy operations across the rails application
40 41 42 43 44 45 |
# File 'lib/mistiq/defaults.rb', line 40 def disable_destroy_ops(strip_links=true) Railtie.get_regex_hash.each { |r,p| set_guard_rule(true,r,strip_links) if r.match(/.*#destroy/) || r.match(/.*#delete/) || r.match(/.*#remove/) } end |
#disable_update_ops(strip_links = true) ⇒ Object
disable all edit operations across the rails application
30 31 32 33 34 35 36 |
# File 'lib/mistiq/defaults.rb', line 30 def disable_update_ops(strip_links=true) Railtie.get_regex_hash.each { |r,p| set_guard_rule(true,r,strip_links) if r.match(/.*#edit/) || r.match(/.*#update/) puts p } end |
#initialize ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mistiq/base.rb', line 2 def initialize super @mode_class = self.class #create hash of keys and condition/consequence pairs @@rules = Hash.new #keep a counter and use it as a key for the hash @@count = 0 #initialize the env variable #that will store the regex for #stripping out links @@redact_hash = Hash.new ENV['REGEX'] = '' puts "Security module has been initialized" end |
#set_guard_on ⇒ Object
checks every time the application runs whether any of the rules is true and applies the specified action
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mistiq/base.rb', line 23 def set_guard_on puts "Guard is on" current_controller = params[:controller] current_action = params[:action] #for each rule check #if the condition is true @@rules.each{ |k,pair| if(pair[0]) #disable the specified controller's action/view pair_array = pair[1].split('#') #only disable view if the current controller #and view are the ones that need to be disabled if(current_controller == pair_array[0] && current_action == pair_array[1]) #if strip_links is true, then #enable link removal if pair[2] disable(pair_array[0],pair_array[1]) else disable_action(pair_array[0],pair_array[1]) end else #if strip_links is true, then #enable link removal if pair[2] remove_links(pair_array[0],pair_array[1]) end end end } end |
#set_guard_rule(condition, consequence, strip_links = true) ⇒ Object
add a new rule to look out for
59 60 61 62 63 64 |
# File 'lib/mistiq/base.rb', line 59 def set_guard_rule(condition, consequence, strip_links=true) pair = [condition,consequence,strip_links] @@rules["#{@@count+=1}"] = pair puts "New rule has been added: #{consequence}, strip links: #{strip_links}" end |