Module: BotAway
- Defined in:
- lib/bot-away.rb,
lib/bot-away/version.rb,
lib/bot-away/middleware.rb,
lib/bot-away/param_parser.rb
Defined Under Namespace
Modules: TestCase, Version Classes: Middleware, ParamParser, Railtie, Spinner
Constant Summary collapse
Class Attribute Summary collapse
-
.dump_params ⇒ Object
Returns the value of attribute dump_params.
-
.obfuscate_honeypot_warning_messages ⇒ Object
writeonly
Sets the attribute obfuscate_honeypot_warning_messages.
-
.show_honeypots ⇒ Object
Returns the value of attribute show_honeypots.
Class Method Summary collapse
- .disabled_for(options = {}) ⇒ Object
-
.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.
-
.excluded?(options) ⇒ Boolean
options include: :controller :action :object_name :method_name.
- .obfuscate_honeypot_warning_messages? ⇒ Boolean
- .reset! ⇒ Object
- .unfiltered_params(*keys) ⇒ Object (also: accepts_unfiltered_params)
- .unfiltered_params_include?(object_name, method_name) ⇒ Boolean
Class Attribute Details
.dump_params ⇒ Object
Returns the value of attribute dump_params.
15 16 17 |
# File 'lib/bot-away.rb', line 15 def dump_params @dump_params end |
.obfuscate_honeypot_warning_messages=(value) ⇒ Object (writeonly)
Sets the attribute obfuscate_honeypot_warning_messages
16 17 18 |
# File 'lib/bot-away.rb', line 16 def (value) @obfuscate_honeypot_warning_messages = value end |
.show_honeypots ⇒ Object
Returns the value of attribute show_honeypots.
15 16 17 |
# File 'lib/bot-away.rb', line 15 def show_honeypots @show_honeypots end |
Class Method Details
.disabled_for(options = {}) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/bot-away.rb', line 83 def disabled_for( = {}) @disabled_for ||= [] if !.empty? @disabled_for << .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.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bot-away.rb', line 60 def disabled_for?() return false if @disabled_for.nil? || .empty? = .stringify_keys @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 if set.key?('controller') && set.key?('action') return true if set['controller'] == ['controller'] && set['action'] == ['action'] elsif set.key?('controller') && !set.key?('action') return true if set['controller'] == ['controller'] elsif set.key?('action') return true if set['action'] == ['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
37 38 39 40 41 42 43 44 |
# File 'lib/bot-away.rb', line 37 def excluded?() = .stringify_keys nonparams = .stringify_keys nonparams.delete 'object_name' nonparams.delete 'method_name' (['object_name'] && ['method_name'] && unfiltered_params_include?(['object_name'], ['method_name'])) || disabled_for?(nonparams) end |
.obfuscate_honeypot_warning_messages? ⇒ Boolean
18 19 20 |
# File 'lib/bot-away.rb', line 18 def !!@obfuscate_honeypot_warning_messages end |
.reset! ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/bot-away.rb', line 91 def reset! self.show_honeypots = false self.dump_params = false self. = true self.unfiltered_params.clear self.disabled_for.clear end |
.unfiltered_params(*keys) ⇒ Object Also known as: accepts_unfiltered_params
22 23 24 25 26 |
# File 'lib/bot-away.rb', line 22 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
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bot-away.rb', line 46 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 |