Class: ThreddedCreateApp::Tasks::AddInvisibleCaptcha

Inherits:
Base
  • Object
show all
Defined in:
lib/thredded_create_app/tasks/add_invisible_captcha.rb

Instance Attribute Summary

Attributes inherited from Base

#app_hostname, #app_name, #app_path, #gems

Instance Method Summary collapse

Methods inherited from Base

#devise_form_fields_begin_pattern, #webpack_js?

Methods included from RunCommand

#run

Methods included from Logging

#log_command, #log_error, #log_info, #log_stderr, #log_verbose, #log_warn, #program_name

Constructor Details

#initialize(simple_form: true, **_args) ⇒ AddInvisibleCaptcha

Returns a new instance of AddInvisibleCaptcha.



7
8
9
10
# File 'lib/thredded_create_app/tasks/add_invisible_captcha.rb', line 7

def initialize(simple_form: true, **_args)
  super
  @simple_form = simple_form
end

Instance Method Details

#after_bundleObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/thredded_create_app/tasks/add_invisible_captcha.rb', line 20

def after_bundle
  inject_into_file 'app/controllers/users/registrations_controller.rb',
                   after: "::Devise::RegistrationsController\n",
                   content: <<-RUBY
    invisible_captcha only: %i[create], honeypot: :name
                   RUBY

  form_view_path = 'app/views/devise/registrations/new.html.erb'
  form_view_captcha = '<%= invisible_captcha :name %>'
  inject_into_file form_view_path,
                   after: devise_form_fields_begin_pattern,
                   content: if @simple_form
                              "    #{form_view_captcha}\n"
                            else
                              "  #{form_view_captcha}\n\n"
                            end
  inject_into_file form_view_path,
                   before: ') do |f|',
                   content: ", html: {autocomplete: 'off'}"

  git_commit 'Add invisible_captcha to the sign up form'
end

#before_bundleObject



16
17
18
# File 'lib/thredded_create_app/tasks/add_invisible_captcha.rb', line 16

def before_bundle
  add_gem 'invisible_captcha'
end

#summaryObject



12
13
14
# File 'lib/thredded_create_app/tasks/add_invisible_captcha.rb', line 12

def summary
  'Add an invisible captcha to the sign up form'
end