Class: Appsignal::CLI::Install Private
- Extended by:
- Helpers
- Defined in:
- lib/appsignal/cli/install.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- EXCLUDED_ENVIRONMENTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
["test"].freeze
Class Method Summary collapse
- .configure(config, environments, name_overwritten) ⇒ Object private
- .configure_rails_app_name(config) ⇒ Object private
- .done_notice ⇒ Object private
- .framework_available?(framework_file) ⇒ Boolean private
- .install_for_capistrano ⇒ Object private
- .install_for_grape(config) ⇒ Object private
- .install_for_hanami(config) ⇒ Object private
- .install_for_padrino(config) ⇒ Object private
- .install_for_rails(config) ⇒ Object private
- .install_for_sinatra(config) ⇒ Object private
- .installed_frameworks ⇒ Object private
- .new_config ⇒ Object private
- .rails_environments ⇒ Object private
-
.run(push_api_key, options) ⇒ Object
private
rubocop:disable Metrics/AbcSize.
- .write_config_file(data) ⇒ Object private
Class Method Details
.configure(config, environments, name_overwritten) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/appsignal/cli/install.rb', line 200 def configure(config, environments, name_overwritten) install_for_capistrano ENV["APPSIGNAL_APP_ENV"] = "development" puts "How do you want to configure AppSignal?" puts " (1) a config file" puts " (2) environment variables" loop do print " Choose (1/2): " case ask_for_input when "1" puts print "Writing config file" periods puts puts colorize " Config file written to config/appsignal.yml", :green write_config_file( :push_api_key => config[:push_api_key], :app_name => config[:name], :environments => environments ) puts break when "2" ENV["APPSIGNAL_ACTIVE"] = "true" ENV["APPSIGNAL_PUSH_API_KEY"] = config[:push_api_key] ENV["APPSIGNAL_APP_NAME"] = config[:name] puts puts "Add the following environment variables to configure AppSignal:" puts " export APPSIGNAL_PUSH_API_KEY=#{config[:push_api_key]}" if name_overwritten puts " export APPSIGNAL_APP_NAME=#{config[:name]}" end puts puts " See the documentation for more configuration options:" puts " https://docs.appsignal.com/gem-settings/configuration.html" press_any_key break end end end |
.configure_rails_app_name(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/appsignal/cli/install.rb', line 86 def configure_rails_app_name(config) loaded = begin load Appsignal::Utils::RailsHelper.application_config_path true rescue LoadError, StandardError false end name_overwritten = false if loaded config[:name] = Appsignal::Utils::RailsHelper.detected_rails_app_name puts name_overwritten = yes_or_no( " Your app's name is: '#{config[:name]}' \n " \ "Do you want to change how this is displayed in AppSignal? " \ "(y/n): " ) if name_overwritten config[:name] = required_input(" Choose app's display name: ") puts end else puts " Unable to automatically detect your Rails app's name." config[:name] = required_input(" Choose your app's display name for AppSignal.com: ") puts end name_overwritten end |
.done_notice ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/appsignal/cli/install.rb', line 244 def done_notice sleep 0.3 puts colorize "#####################################", :green puts colorize "## AppSignal installation complete ##", :green puts colorize "#####################################", :green sleep 0.3 puts if Gem.win_platform? puts "The AppSignal agent currently does not work on Microsoft " \ "Windows. Please push these changes to your staging/production " \ "environment and make sure some actions are performed. " \ "AppSignal should pick up your app after a few minutes." else puts " Sending example data to AppSignal..." if Appsignal::Demo.transmit puts " Example data sent!" puts " It may take about a minute for the data to appear on https://appsignal.com/accounts" puts puts " Please return to your browser and follow the instructions." else puts " Couldn't start the AppSignal agent and send example data to AppSignal.com" puts " Please use `appsignal diagnose` to debug your configuration." end end end |
.framework_available?(framework_file) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
283 284 285 286 287 288 |
# File 'lib/appsignal/cli/install.rb', line 283 def framework_available?(framework_file) require framework_file true rescue LoadError false end |
.install_for_capistrano ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/appsignal/cli/install.rb', line 185 def install_for_capistrano capfile = File.join(Dir.pwd, "Capfile") return unless File.exist?(capfile) return if File.read(capfile) =~ %r{require ['|"]appsignal/capistrano} puts "Installing for Capistrano" print " Adding AppSignal integration to Capfile" File.open(capfile, "a") do |f| f.write "\nrequire 'appsignal/capistrano'\n" end periods puts puts end |
.install_for_grape(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/appsignal/cli/install.rb', line 152 def install_for_grape(config) puts "Installing for Grape" config[:name] = required_input(" Enter application name: ") puts configure(config, %w[development production staging], true) puts "Manual Grape configuration needed" puts " See the installation instructions at:" puts " https://docs.appsignal.com/ruby/integrations/grape.html" press_any_key done_notice end |
.install_for_hanami(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/appsignal/cli/install.rb', line 167 def install_for_hanami(config) puts "Installing for Hanami" config[:name] = required_input(" Enter application name: ") puts configure(config, %w[development production staging], true) puts "Finish Hanami installation" puts " Hanami requires some manual configuration." puts " After installing the gem, add the following line to config.ru:" puts puts " require 'appsignal/integrations/hanami'" puts puts " You can find more information in the documentation:" puts " https://docs.appsignal.com/ruby/integrations/hanami.html" press_any_key done_notice end |
.install_for_padrino(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/appsignal/cli/install.rb', line 134 def install_for_padrino(config) puts "Installing for Padrino" config[:name] = required_input(" Enter application name: ") puts configure(config, %w[development production staging], true) puts "Finish Padrino installation" puts " Padrino requires some manual configuration." puts " After installing the gem, add the following line to /config/boot.rb:" puts puts " require 'appsignal/integrations/padrino" puts puts " You can find more information in the documentation:" puts " https://docs.appsignal.com/ruby/integrations/padrino.html" press_any_key done_notice end |
.install_for_rails(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 81 82 83 84 |
# File 'lib/appsignal/cli/install.rb', line 78 def install_for_rails(config) puts "Installing for Ruby on Rails" name_overwritten = configure_rails_app_name(config) configure(config, rails_environments, name_overwritten) done_notice end |
.install_for_sinatra(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/appsignal/cli/install.rb', line 116 def install_for_sinatra(config) puts "Installing for Sinatra" config[:name] = required_input(" Enter application name: ") puts configure(config, %w[development production staging], true) puts "Finish Sinatra configuration" puts " Sinatra requires some manual configuration." puts " Add this line beneath require 'sinatra':" puts puts " require 'appsignal/integrations/sinatra'" puts puts " You can find more information in the documentation:" puts " https://docs.appsignal.com/ruby/integrations/sinatra.html" press_any_key done_notice end |
.installed_frameworks ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/appsignal/cli/install.rb', line 270 def installed_frameworks [].tap do |out| if framework_available?("rails") && File.exist?(Appsignal::Utils::RailsHelper.application_config_path) out << :rails end out << :sinatra if framework_available? "sinatra" out << :padrino if framework_available? "padrino" out << :grape if framework_available? "grape" out << :hanami if framework_available? "hanami" end end |
.new_config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
313 314 315 |
# File 'lib/appsignal/cli/install.rb', line 313 def new_config Appsignal::Config.new(Dir.pwd, "") end |
.rails_environments ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
290 291 292 293 294 |
# File 'lib/appsignal/cli/install.rb', line 290 def rails_environments Dir.glob( File.join(Dir.pwd, "config/environments/*.rb") ).map { |o| File.basename(o, ".rb") }.sort - EXCLUDED_ENVIRONMENTS end |
.run(push_api_key, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Metrics/AbcSize
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/appsignal/cli/install.rb', line 16 def run(push_api_key, ) # rubocop:disable Metrics/AbcSize self.coloring = .delete(:color) { true } $stdout.sync = true puts puts colorize "#######################################", :green puts colorize "## Starting AppSignal Installer ##", :green puts colorize "## --------------------------------- ##", :green puts colorize "## Need help? support@appsignal.com ##", :green puts colorize "## Docs? docs.appsignal.com ##", :green puts colorize "#######################################", :green puts unless push_api_key puts colorize "Problem encountered:", :red puts " No push API key entered." puts " - Sign up for AppSignal and follow the instructions" puts " - Already signed up? Click 'Add app' on the account overview page" puts puts colorize "Exiting installer...", :red return end config = new_config config[:push_api_key] = push_api_key print "Validating API key" periods puts begin auth_check = Appsignal::AuthCheck.new(config) unless auth_check.perform == "200" puts "\n API key '#{config[:push_api_key]}' is not valid, please get a new one on https://appsignal.com" return end rescue => e puts " There was an error validating your API key:" puts colorize "'#{e}'", :red puts " Please try again" return end puts colorize " API key valid!", :green puts if installed_frameworks.include?(:rails) install_for_rails(config) elsif installed_frameworks.include?(:padrino) install_for_padrino(config) elsif installed_frameworks.include?(:grape) install_for_grape(config) elsif installed_frameworks.include?(:hanami) install_for_hanami(config) elsif installed_frameworks.include?(:sinatra) install_for_sinatra(config) else print colorize "Warning:", :red puts " We could not detect which framework you are using. "\ "We'd be very grateful if you email us on support@appsignal.com "\ "with information about your setup." puts done_notice end end |
.write_config_file(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/appsignal/cli/install.rb', line 296 def write_config_file(data) filename = File.join( File.dirname(__FILE__), "../../../resources/appsignal.yml.erb" ) file_contents = File.read(filename) template = if ruby_2_6_or_up? ERB.new(file_contents, :trim_mode => "-") else ERB.new(file_contents, nil, "-") end config = template.result(OpenStruct.new(data).instance_eval { binding }) FileUtils.mkdir_p(File.join(Dir.pwd, "config")) File.write(File.join(Dir.pwd, "config/appsignal.yml"), config) end |