Class: NewRelic::Command::Install

Inherits:
NewRelic::Command show all
Defined in:
lib/new_relic/commands/install.rb

Constant Summary collapse

NO_LICENSE_KEY =
"<PASTE LICENSE KEY HERE>"

Instance Attribute Summary collapse

Attributes inherited from NewRelic::Command

#leftover

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NewRelic::Command

#err, #info, inherited, run

Constructor Details

#initialize(command_line_args = {}) ⇒ Install

Returns a new instance of Install.

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/new_relic/commands/install.rb', line 20

def initialize command_line_args={}
  super command_line_args
  if !@dest_dir
    # Install a newrelic.yml file into the local config directory.
    if File.directory? "config"
      @dest_dir = "config"
    else
      @dest_dir = "."
    end
  end
  @license_key ||= NO_LICENSE_KEY
  @app_name ||= @leftover
  raise CommandFailure.new("Application name required.", @options) unless @app_name && @app_name.size > 0
  @generated_for_user ||= @user_string || ""
end

Instance Attribute Details

#app_nameObject (readonly)

Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.

Will throw CommandFailed exception if there’s any error.



19
20
21
# File 'lib/new_relic/commands/install.rb', line 19

def app_name
  @app_name
end

#dest_dirObject (readonly)

Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.

Will throw CommandFailed exception if there’s any error.



19
20
21
# File 'lib/new_relic/commands/install.rb', line 19

def dest_dir
  @dest_dir
end

#generated_for_userObject (readonly)

Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.

Will throw CommandFailed exception if there’s any error.



19
20
21
# File 'lib/new_relic/commands/install.rb', line 19

def generated_for_user
  @generated_for_user
end

#license_keyObject (readonly)

Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.

Will throw CommandFailed exception if there’s any error.



19
20
21
# File 'lib/new_relic/commands/install.rb', line 19

def license_key
  @license_key
end

#quietObject (readonly)

Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.

Will throw CommandFailed exception if there’s any error.



19
20
21
# File 'lib/new_relic/commands/install.rb', line 19

def quiet
  @quiet
end

#src_fileObject (readonly)

Use -h to see options. When command_line_args is a hash, we are invoking directly and it’s treated as an options with optional string values for :user, :description, :appname, :revision, :environment, and :changes.

Will throw CommandFailed exception if there’s any error.



19
20
21
# File 'lib/new_relic/commands/install.rb', line 19

def src_file
  @src_file
end

Class Method Details

.commandObject



9
# File 'lib/new_relic/commands/install.rb', line 9

def self.command; "install"; end

Instance Method Details

#contentObject



62
63
64
65
66
# File 'lib/new_relic/commands/install.rb', line 62

def content
  @src_file ||= File.expand_path(File.join(File.dirname(__FILE__),"..","..","..","newrelic.yml"))
  template = File.read(@src_file)
  ERB.new(template).result(binding)
end

#runObject



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
# File 'lib/new_relic/commands/install.rb', line 36

def run
  dest_file = File.expand_path(@dest_dir + "/newrelic.yml")
  if File.exist?(dest_file)
    raise NewRelic::Command::CommandFailure, "newrelic.yml file already exists.  Move it out of the way."
  end
  File.open(dest_file, 'w') { | out | out.puts(content) }

  puts <<-EOF unless quiet

Installed a default configuration file at
#{dest_file}.
  EOF
  puts <<-EOF unless quiet || @license_key != NO_LICENSE_KEY

To monitor your application in production mode, sign up for an account
at www.newrelic.com, and replace the newrelic.yml file with the one
you receive upon registration.
  EOF
  puts <<-EOF unless quiet

E-mail [email protected] with any problems or questions.

  EOF

end