Class: Ibrain::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Ibrain::InstallGenerator
- Defined in:
- lib/generators/ibrain/install/install_generator.rb
Constant Summary collapse
- CORE_MOUNT_ROUTE =
"mount Ibrain::Core::Engine"
Instance Method Summary collapse
- #add_files ⇒ Object
- #additional_tweaks ⇒ Object
- #complete ⇒ Object
- #configure_application ⇒ Object
- #create_overrides_directory ⇒ Object
- #install_auth_plugin ⇒ Object
- #install_routes ⇒ Object
- #plugin_install_preparation ⇒ Object
- #run_bundle_install_if_needed_by_plugins ⇒ Object
Instance Method Details
#add_files ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 126 def add_files template 'config/initializers/ibrain.rb.tt', 'config/initializers/ibrain.rb', { skip: true } template 'config/initializers/cors.tt', 'config/initializers/cors.rb' template 'config/puma.tt', 'config/puma.rb' yml_template 'config/database.tt', 'config/database.yml' template 'rubocop.yml.tt', '.rubocop.yml' if [:with_rubocop] if [:with_graphql] template 'graphql/app_schema.rb.tt', 'app/graphql/app_schema.rb', { skip: true } template 'graphql/types/mutation_type.rb.tt', 'app/graphql/types/mutation_type.rb', { skip: true } template 'graphql/types/query_type.rb.tt', 'app/graphql/types/query_type.rb', { skip: true } end end |
#additional_tweaks ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 21 def additional_tweaks return unless File.exist? 'public/robots.txt' append_file "public/robots.txt", <<-ROBOTS.strip_heredoc User-agent: * Disallow: /user Disallow: /account Disallow: /api Disallow: /password ROBOTS end |
#complete ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 140 def complete unless [:quiet] Ibrain::Logger.info "*" * 50 Ibrain::Logger.info "Ibrain has been installed successfully. You're all ready to go!" Ibrain::Logger.info " " Ibrain::Logger.info "Enjoy!" end end |
#configure_application ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 37 def configure_application if ![:enforce_available_locales].nil? application <<-RUBY I18n.enforce_available_locales = #{[:enforce_available_locales]} RUBY end end |
#create_overrides_directory ⇒ Object
33 34 35 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 33 def create_overrides_directory empty_directory "app/overrides" end |
#install_auth_plugin ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 50 def install_auth_plugin if [:with_authentication] && ([:auto_accept] || !no?(" Ibrain has a default authentication extension that uses Devise. You can find more info at https://github.com/john-techfox/ibrain-auth.git. Would you like to install it? (Y/n)")) @plugins_to_be_installed << 'ibrain-auth' unless system('gem list | grep ibrain-auth') @plugin_generators_to_run << "ibrain:auth:install --with-ridgpole=#{[:with_ridgepole]}" end end |
#install_routes ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 100 def install_routes routes_file_path = File.join('config', 'routes.rb') unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do <<-RUBY # This line mounts Ibrain's routes at the root of your application. # This means, any requests to URLs such as /graphql, will go to Ibrain::GraphqlController, # any requests to URLS such as /auth, will go to Ibrain::AuthController, # If you would like to change where this engine is mounted, simply change the :at option to something different. # # We ask that you don't use the :as option here, as Ibrain relies on it being the default of "ibrain" #{CORE_MOUNT_ROUTE}, at: '/' # Please contact to Tai Nguyen Van <[email protected]> if you have any question? RUBY end end unless [:quiet] Ibrain::Logger.info "*" * 50 Ibrain::Logger.info "We added the following line to your application's config/routes.rb file:" Ibrain::Logger.info " " Ibrain::Logger.info " #{CORE_MOUNT_ROUTE}, at: '/'" end end |
#plugin_install_preparation ⇒ Object
45 46 47 48 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 45 def plugin_install_preparation @plugins_to_be_installed = [] @plugin_generators_to_run = [] end |
#run_bundle_install_if_needed_by_plugins ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/generators/ibrain/install/install_generator.rb', line 62 def run_bundle_install_if_needed_by_plugins @plugins_to_be_installed.each do |plugin_name| gem plugin_name end if [:with_rubocop] append_gem('rubocop', '1.23.0', 'development') append_gem('rubocop-performance', '1.12.0', 'development') append_gem('rubocop-rails', '2.12.4', 'development') append_gem('rubocop-graphql', '0.11.2', 'development') end if [:with_graphql] append_gem('graphql', '1.12.6') append_gem('graphql-batch', '0.4.3') append_gem('graphql-guard', '2.0.0') append_gem('graphql-rails-generators', '1.1.2', 'development') append_gem('graphiql-rails', '1.8.0', 'development') append_gem('apollo_upload_server', '2.1') end append_gem('annotate', '3.1.1', 'development') if [:with_annotation] append_gem('sendgrid-ruby', '6.6.0') if [:with_sendgrid] if [:with_ridgepole] append_gem('ridgepole', '1.0.0', 'development') else remove_gem('ridgepole') end bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any? run "spring stop" if defined?(Spring) @plugin_generators_to_run.each do |plugin_generator_name| generate plugin_generator_name.to_s end end |