Class: EncodedId::Rails::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- EncodedId::Rails::Generators::InstallGenerator
- Defined in:
- lib/generators/encoded_id/rails/install_generator.rb
Overview
The Install generator ‘encoded_id:rails:install`
Instance Method Summary collapse
Instance Method Details
#ask_for_encoder ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/encoded_id/rails/install_generator.rb', line 20 def ask_for_encoder @encoder = [:encoder] @encoder ||= ask("Which encoder would you like to use?", limited_to: %w[sqids hashids], default: "sqids") unless %w[sqids hashids].include?(@encoder) say "Invalid encoder '#{@encoder}'. Must be 'sqids' or 'hashids'.", :red exit 1 end end |
#copy_tasks ⇒ Object
33 34 35 36 |
# File 'lib/generators/encoded_id/rails/install_generator.rb', line 33 def copy_tasks template_name = (@encoder == "sqids") ? "sqids_encoded_id.rb" : "hashids_encoded_id.rb" template "templates/#{template_name}", "config/initializers/encoded_id.rb" end |
#show_readme ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/encoded_id/rails/install_generator.rb', line 38 def show_readme say "\n" + ("=" * 70), :green if @encoder == "sqids" say "Sqids encoder installed!", :green say "This encoder does not require a salt and generates URL-safe IDs.", :green else say "Hashids encoder installed!", :green say "⚠️ IMPORTANT: You MUST configure a salt in config/initializers/encoded_id.rb", :yellow say "Uncomment and set the 'config.salt' line before using Hashids.", :yellow end say ("=" * 70) + "\n", :green end |