Class: Maquina::Generators::RackAttackGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Maquina::Generators::RackAttackGenerator
- Defined in:
- lib/generators/maquina/rack_attack/rack_attack_generator.rb
Instance Method Summary collapse
-
#add_gem ⇒ Object
2.
-
#create_initializer ⇒ Object
1.
-
#run_bundle_install ⇒ Object
3.
-
#show_post_install ⇒ Object
4.
Instance Method Details
#add_gem ⇒ Object
-
Add gem to Gemfile
18 19 20 21 22 23 24 25 26 |
# File 'lib/generators/maquina/rack_attack/rack_attack_generator.rb', line 18 def add_gem gemfile_path = File.join(destination_root, "Gemfile") if File.exist?(gemfile_path) content = File.read(gemfile_path) unless content.include?('gem "rack-attack"') append_to_file "Gemfile", "\ngem \"rack-attack\"\n" end end end |
#create_initializer ⇒ Object
-
Initializer
12 13 14 15 |
# File 'lib/generators/maquina/rack_attack/rack_attack_generator.rb', line 12 def create_initializer template "config/initializers/rack_attack.rb.tt", "config/initializers/rack_attack.rb" end |
#run_bundle_install ⇒ Object
-
Bundle install
29 30 31 32 33 34 35 |
# File 'lib/generators/maquina/rack_attack/rack_attack_generator.rb', line 29 def run_bundle_install return unless rails_app? Bundler.with_unbundled_env do system("bundle install", chdir: destination_root) end end |
#show_post_install ⇒ Object
-
Post-install message
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/maquina/rack_attack/rack_attack_generator.rb', line 38 def show_post_install return if [:quiet] say "" say "Rack::Attack has been installed!", :green say "" say "Default protections enabled:", :yellow say " - Blocklist: PHP files, WordPress paths, sensitive files, scanner targets" say " - Safelist: localhost (127.0.0.1, ::1)" say " - Throttle: 300 req/5min per IP, 5 login attempts/20s per IP" say "" say "Customize rules in config/initializers/rack_attack.rb" say "" end |