Class: JwtApi::SetupGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- JwtApi::SetupGenerator
- Defined in:
- lib/generators/jwt_api/setup_generator.rb
Instance Method Summary collapse
- #add_api_namespace_to_routes ⇒ Object
- #copy_api_controllers ⇒ Object
- #copy_jwt_class ⇒ Object
- #copy_password_reset_mailer ⇒ Object
- #copy_password_reset_views ⇒ Object
- #copy_user_views ⇒ Object
- #generate_jti_migration ⇒ Object
- #source_paths ⇒ Object
Instance Method Details
#add_api_namespace_to_routes ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/jwt_api/setup_generator.rb', line 15 def add_api_namespace_to_routes routes = 'config/routes.rb' inject_into_file routes, after: 'Rails.application.routes.draw do' do # TODO: this is ugly, there has to be a better way to do this "\n\n# API routes namespace :api, defaults: { format: :json } do namespace :v1 do # Auth post 'auth' => 'authentication#authenticate_user' delete 'auth' => 'authentication#logout' # Users resource :users get 'me' => 'users#me' # User Password Reset Flow post 'passwords/reset' => 'passwords#reset_password_instructions' get 'passwords/verify' => 'passwords#verify' post 'passwords/update' => 'passwords#update_password' end end\n\n" end end |
#copy_api_controllers ⇒ Object
11 12 13 |
# File 'lib/generators/jwt_api/setup_generator.rb', line 11 def copy_api_controllers directory 'templates/api', 'app/controllers/api' end |
#copy_jwt_class ⇒ Object
49 50 51 |
# File 'lib/generators/jwt_api/setup_generator.rb', line 49 def copy_jwt_class copy_file 'templates/initializers/json_web_token.rb', 'config/initializers/json_web_token.rb' end |
#copy_password_reset_mailer ⇒ Object
41 42 43 |
# File 'lib/generators/jwt_api/setup_generator.rb', line 41 def copy_password_reset_mailer copy_file 'templates/mailers/jwt_mailer.rb', 'app/mailers/jwt_mailer.rb' end |
#copy_password_reset_views ⇒ Object
45 46 47 |
# File 'lib/generators/jwt_api/setup_generator.rb', line 45 def copy_password_reset_views directory 'templates/views/jwt_mailer', 'app/views/jwt_mailer' end |
#copy_user_views ⇒ Object
37 38 39 |
# File 'lib/generators/jwt_api/setup_generator.rb', line 37 def copy_user_views directory 'templates/views/users', 'app/views/users' end |
#generate_jti_migration ⇒ Object
53 54 55 |
# File 'lib/generators/jwt_api/setup_generator.rb', line 53 def generate_jti_migration generate 'migration', 'add_jti_to_users', 'jti:string:uniq:index' end |
#source_paths ⇒ Object
7 8 9 |
# File 'lib/generators/jwt_api/setup_generator.rb', line 7 def source_paths [__dir__] end |