Class: GraphqlDevise::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- GraphqlDevise::InstallGenerator
- Defined in:
- lib/generators/graphql_devise/install_generator.rb
Instance Method Summary collapse
- #execute_devise_installer ⇒ Object
- #execute_dta_installer ⇒ Object
- #mount_in_schema ⇒ Object
- #mount_resource_route ⇒ Object
- #replace_controller_concern ⇒ Object
- #replace_model_concern ⇒ Object
- #set_change_headers_on_each_request_false ⇒ Object
Instance Method Details
#execute_devise_installer ⇒ Object
12 13 14 |
# File 'lib/generators/graphql_devise/install_generator.rb', line 12 def execute_devise_installer generate 'devise:install' end |
#execute_dta_installer ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/graphql_devise/install_generator.rb', line 16 def execute_dta_installer # Necessary in case of a re-run of the generator, for DTA to detect concerns already included if File.exist?(File.("app/models/#{user_class.underscore}.rb", destination_root)) gsub_file( "app/models/#{user_class.underscore}.rb", 'GraphqlDevise::Authenticatable', 'DeviseTokenAuth::Concerns::User' ) end gsub_file( 'app/controllers/application_controller.rb', 'GraphqlDevise::SetUserByToken', 'DeviseTokenAuth::Concerns::SetUserByToken' ) generate 'devise_token_auth:install', "#{user_class} #{mount_path}" end |
#mount_in_schema ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/generators/graphql_devise/install_generator.rb', line 77 def mount_in_schema return if ['mount'] == 'separate_route' inject_into_file "app/graphql/#{['mount'].underscore}.rb", after: "< GraphQL::Schema\n" do <<-RUBY use GraphqlDevise::SchemaPlugin.new( query: Types::QueryType, mutation: Types::MutationType, resource_loaders: [ GraphqlDevise::ResourceLoader.new(#{user_class}) ] ) RUBY end end |
#mount_resource_route ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/graphql_devise/install_generator.rb', line 34 def mount_resource_route routes_file = 'config/routes.rb' dta_route = "mount_devise_token_auth_for '#{user_class}', at: '#{mount_path}'" if ['mount'] != 'separate_route' gsub_file(routes_file, /^\s+#{Regexp.escape(dta_route + "\n")}/i, '') else gem_route = "mount_graphql_devise_for #{user_class}, at: '#{mount_path}'" if file_contains_str?(routes_file, gem_route) gsub_file(routes_file, /^\s+#{Regexp.escape(dta_route + "\n")}/i, '') say_status('skipped', "Routes already exist for #{user_class} at #{mount_path}") else gsub_file(routes_file, /#{Regexp.escape(dta_route)}/i, gem_route) end end end |
#replace_controller_concern ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/generators/graphql_devise/install_generator.rb', line 61 def replace_controller_concern gsub_file( 'app/controllers/application_controller.rb', /^\s+include DeviseTokenAuth::Concerns::SetUserByToken/, ' include GraphqlDevise::SetUserByToken' ) end |
#replace_model_concern ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/generators/graphql_devise/install_generator.rb', line 53 def replace_model_concern gsub_file( "app/models/#{user_class.underscore}.rb", /^\s+include DeviseTokenAuth::Concerns::User/, ' include GraphqlDevise::Authenticatable' ) end |
#set_change_headers_on_each_request_false ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/generators/graphql_devise/install_generator.rb', line 69 def set_change_headers_on_each_request_false gsub_file( 'config/initializers/devise_token_auth.rb', '# config.change_headers_on_each_request = true', 'config.change_headers_on_each_request = false' ) end |