Module: BotAway

Defined in:
lib/bot-away.rb,
lib/bot-away/param_parser.rb

Defined Under Namespace

Classes: ParamParser, Spinner

Constant Summary collapse

VERSION =
File.read(File.join(File.dirname(__FILE__), "../VERSION"))

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dump_paramsObject

Returns the value of attribute dump_params.



17
18
19
# File 'lib/bot-away.rb', line 17

def dump_params
  @dump_params
end

.show_honeypotsObject

Returns the value of attribute show_honeypots.



17
18
19
# File 'lib/bot-away.rb', line 17

def show_honeypots
  @show_honeypots
end

Class Method Details

.disabled_for(options = {}) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/bot-away.rb', line 81

def disabled_for(options = {})
  @disabled_for ||= []
  if !options.empty?
    @disabled_for << options.stringify_keys
  end
  @disabled_for
end

.disabled_for?(options) ⇒ Boolean

Returns true if the given options match the options set via #disabled_for, or if the Rails run mode matches any run modes set via #disabled_for.

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bot-away.rb', line 55

def disabled_for?(options)
  return false if @disabled_for.nil? || options.empty?
  options = options.stringify_keys
#      p options
#      p "===="
  @disabled_for.each do |set|
    if set.key?('mode')
      next unless ENV['RAILS_ENV'] == set['mode'].to_s
      return true if set.keys.length == 1
      # if there are more keys, then it looks something like:
      #   disabled_for :mode => 'development', :controller => 'tests'
      # and that means we need to check the next few conditions.
    end
    
#        p set
    if set.key?('controller') && set.key?('action')
      return true if set['controller'] == options['controller'] && set['action'] == options['action']
    elsif set.key?('controller') && !set.key?('action')
      return true if set['controller'] == options['controller']
    elsif set.key?('action')
      return true if set['action'] == options['action']
    end
  end
  false
end

.excluded?(options) ⇒ Boolean

options include:

:controller
:action
:object_name
:method_name

excluded? will also check the current Rails run mode against disabled_for

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/bot-away.rb', line 34

def excluded?(options)
  options = options.stringify_keys
  nonparams = options.stringify_keys.without('object_name', 'method_name')
  (options['object_name'] && options['method_name'] &&
          unfiltered_params_include?(options['object_name'], options['method_name'])) || disabled_for?(nonparams)
end

.reset!Object



89
90
91
92
93
94
# File 'lib/bot-away.rb', line 89

def reset!
  self.show_honeypots = false
  self.dump_params = false
  self.unfiltered_params.clear
  self.disabled_for.clear
end

.unfiltered_params(*keys) ⇒ Object Also known as: accepts_unfiltered_params



19
20
21
22
23
# File 'lib/bot-away.rb', line 19

def unfiltered_params(*keys)
  unfiltered_params = instance_variable_get("@unfiltered_params") || instance_variable_set("@unfiltered_params", [])
  unfiltered_params.concat keys.flatten.collect { |k| k.to_s }
  unfiltered_params
end

.unfiltered_params_include?(object_name, method_name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bot-away.rb', line 41

def unfiltered_params_include?(object_name, method_name)
  unfiltered_params.collect! { |u| u.to_s }
  if (object_name &&
          (unfiltered_params.include?(object_name.to_s) ||
                  unfiltered_params.include?("#{object_name}[#{method_name}]")) ||
      unfiltered_params.include?(method_name.to_s))
    true
  else
    false
  end
end