Module: MeadCaptcha::Helpers
- Defined in:
- lib/mead_captcha/helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #honeypot_present? ⇒ Boolean
- #mead_params(masked = nil, parameterize: true) ⇒ Object
- #on_honeypot_failure ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 |
# File 'lib/mead_captcha/helpers.rb', line 3 def self.included(base) helper_methods = self.protected_instance_methods base.send :helper_method, helper_methods end |
Instance Method Details
#honeypot_present? ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mead_captcha/helpers.rb', line 13 def honeypot_present? honeypot_params = params.permit!.to_hash honeypot_params.extend Hashie::Extensions::DeepFind honeypot_field_names.each do |honeypot| return true if honeypot_params.deep_find(honeypot).present? end false rescue StandardError => e false end |
#mead_params(masked = nil, parameterize: true) ⇒ Object
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 |
# File 'lib/mead_captcha/helpers.rb', line 27 def mead_params(masked = nil, parameterize: true) masked = if masked.nil? params.permit!.to_hash elsif masked.is_a?(ActionController::Parameters) masked.permit!.to_hash else masked end unmasked = {} masked.map do |key, value| key = deobfuscate(key) if value.is_a? Hash value = mead_params(value, parameterize: false) elsif value.is_a? Array value = value.flat_map { |v| mead_params(v, parameterize: false) } end unmasked[key] = value end if parameterize ActionController::Parameters.new(unmasked) else unmasked end end |
#on_honeypot_failure ⇒ Object
9 10 11 |
# File 'lib/mead_captcha/helpers.rb', line 9 def on_honeypot_failure head :ok if honeypot_present? end |