Vamos ver como é importante fazer sua gem saber gerar códigos para a instalação dela mesmo junto ao Rails e como é importante importante documentar bem.
in process 95922 Usage: rails generate GENERATOR [args] [options] General options: -h, [--help] # Print generator's options and usage -p, [--pretend] # Run but do not make any changes -f, [--force] # Overwrite files that already exist -s, [--skip] # Skip files that already exist -q, [--quiet] # Suppress status output Please choose a generator below. … … ?
95922 Usage: rails generate GENERATOR [args] [options] General options: -h, [--help] # Print generator's options and usage -p, [--pretend] # Run but do not make any changes -f, [--force] # Overwrite files that already exist -s, [--skip] # Skip files that already exist -q, [--quiet] # Suppress status output Please choose a generator below. … … MyGemName: my_gem_name:initializer
desc "This generator creates an initializer file at config/initializers” create_file "config/initializers/initializer2.rb", “# Seu código aqui" end end end end lib/generators/my_gem_name/initializer_generator.rb
process 98283 Usage: rails generate my_gem_name:initializer NAME [options] Options: [--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated applications) Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist This generator creates an initializer file at config/initializers
process 98741 Usage: rails generate my_gem_name:initializer NAME [options] Options: [--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolate applications) Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist Description: Explicação sobre o que minha Gem faz Example: rails generate my_gem_name:initializer This will create: config/initializers/my_gem_initializer.rb
__FILE__) # desc "This generator creates an initializer file at config/initializers" def copy_initializer copy_file "my_gem_initializer.rb", "config/initializers/my_gem_initializer.rb" end end end end lib/generators/my_gem_name/initializer_generator.rb