lib/capistrano/recipes/newrelic.rb in marcosgz-cap-recipe-0.0.8 vs lib/capistrano/recipes/newrelic.rb in marcosgz-cap-recipe-0.0.9
- old
+ new
@@ -1,21 +1,32 @@
-# Example
-# =======
-#
-# newrelic_setup_settings:
-# common:
-# app_name: AppName
-# license_key: secret
-# staging:
-# app_name: AppName (Staging)
-
Capistrano::Configuration.instance(:must_exist).load do
- set(:newrelic_remote_file) { File.join(shared_path, 'config/newrelic.yml') } unless exists?(:newrelic_remote_file)
- set(:newrelic_template, 'newrelic.yml.erb') unless exists?(:newrelic_template)
+ # Required attributes
+ # ===================
+ # *license_key* 123xyz
+ # *app_name* Production App
+ namespace :newrelic do
+ namespace :setup do
+ desc "Upload configs"
+ task :default, :roles => :app do
+ if exists?(:newrelic_setup_settings)
+ set(:recipe_settings) { newrelic_template_settings }
+ put template.render(_newrelic_template), _newrelic_remote_path
+ else
+ puts "[FATAL] - Newrelic template settings were not found"
+ abort
+ end
+ end
+ desc "Download configs"
+ task :get, :roles => :db do
+ download _newrelic_remote_path, _newrelic_local_path
+ end
+ end
+ end
+
def newrelic_setup_defaults
- {
+ HashWithIndifferentAccess.new({
'common' => {
# ============================== LICENSE KEY ===============================
# You must specify the license key associated with your New Relic
# account. This key binds your Agent's data to your account in the
@@ -173,41 +184,24 @@
},
'development' => {'developer_mode' => true},
'staging' => {'developer_mode' => true},
'test' => {},
'production' => {'monitor_mode' => true}
- }
+ }.reverse_merge(default_rails_environments_hash))
end
- # task: `newrelic:setup'
def newrelic_template_settings
- fetch(:newrelic_setup_settings, {}).reverse_merge(
- newrelic_setup_defaults.keys.inject({}) {|r, e| r.merge Hash[e, Hash.new] }
- ).inject({}) do |r, (k,v)|
- r.merge Hash[k, v.reverse_merge(newrelic_setup_defaults[k] || {})]
- end
+ DeepToHash.to_hash newrelic_setup_defaults.deep_merge(fetch(:newrelic_setup_settings, {}))
end
- # Required attributes
- # ===================
- # *license_key* 123xyz
- # *app_name* Production App
- namespace :newrelic do
- namespace :setup do
- desc "Upload configs"
- task :default, :roles => :app do
- if exists?(:newrelic_setup_settings)
- set(:recipe_settings) { newrelic_template_settings }
- put template.render(fetch(:newrelic_template)), fetch(:newrelic_remote_file)
- else
- puts "[FATAL] - Newrelic template settings were not found"
- abort
- end
- end
+ def _newrelic_remote_path
+ File.join(shared_path, fetch(:newrelic_remote_path, 'config/newrelic.yml'))
+ end
- desc "Download configs"
- task :get, :roles => :db do
- download fetch(:newrelic_remote_file), File.join(local_rails_root, 'config/newrelic.yml')
- end
- end
+ def _newrelic_local_path
+ File.join(local_rails_root, fetch(:newrelic_local_path, 'config/newrelic.yml'))
+ end
+
+ def _newrelic_template
+ fetch(:newrelic_template, 'newrelic.yml.erb')
end
end