lib/rails/generators/hoptoad/hoptoad_generator.rb in hoptoad_notifier-2.3.10 vs lib/rails/generators/hoptoad/hoptoad_generator.rb in hoptoad_notifier-2.3.11
- old
+ new
@@ -12,10 +12,11 @@
def install
ensure_api_key_was_configured
ensure_plugin_is_not_present
append_capistrano_hook
generate_initializer unless api_key_configured?
+ determine_api_key if heroku?
test_hoptoad
end
private
@@ -51,9 +52,29 @@
end
end
def generate_initializer
template 'initializer.rb', 'config/initializers/hoptoad.rb'
+ end
+
+ def determine_api_key
+ puts "Attempting to determine your API Key from Heroku..."
+ ENV['HOPTOAD_API_KEY'] = `heroku console 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
+ if ENV['HOPTOAD_API_KEY'].blank?
+ puts "... Failed."
+ puts "WARNING: We were unable to detect the Hoptoad API Key from your Heroku environment."
+ puts "Your Heroku application environment may not be configured correctly."
+ exit 1
+ else
+ puts "... Done."
+ puts "Heroku's Hoptoad API Key is '#{ENV['HOPTOAD_API_KEY']}'"
+ end
+ end
+
+ def heroku?
+ options[:heroku] ||
+ system("grep HOPTOAD_API_KEY config/initializers/hoptoad.rb") ||
+ system("grep HOPTOAD_API_KEY config/environment.rb")
end
def api_key_configured?
File.exists?('config/initializers/hoptoad.rb')
end