Class: Settings

Inherits:
Settingslogic
  • Object
show all
Defined in:
lib/rest-ftp-daemon/settings.rb

Overview

Configuration class

Instance Method Summary collapse

Instance Method Details

#at(*path) ⇒ Object

Direct access to any depth



11
12
13
# File 'lib/rest-ftp-daemon/settings.rb', line 11

def at *path
  path.reduce(Settings) { |m, key| m && m[key.to_s] }
end

#dumpObject

Dump whole settings set to readable YAML



16
17
18
# File 'lib/rest-ftp-daemon/settings.rb', line 16

def dump
  to_hash.to_yaml(indent: 4, useheader: true, useversion: false )
end

#init_defaultsObject



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
# File 'lib/rest-ftp-daemon/settings.rb', line 24

def init_defaults
  # Init host if missing
  Settings["host"] ||= `hostname`.to_s.chomp.split(".").first

  # Init PID file name if missing
  Settings["pidfile"] ||= "/tmp/#{APP_NICK}-#{Settings['host']}-#{Settings['port']}.pid"

  # Init NEWRELIC env
  if Settings.newrelic_enabled?
    # Enable module
    ENV["NEWRELIC_AGENT_ENABLED"] = "true"
    ENV["NEW_RELIC_MONITOR_MODE"] = "true"

    # License
    ENV["NEW_RELIC_LICENSE_KEY"] = Settings.at(:newrelic, :licence)

    # Appname
    platform = Settings.newrelic[:platform] || Settings["host"]
    Settings.newrelic[:app_name] ||= "#{APP_NICK}-#{platform}-#{Settings.namespace}"
    ENV["NEW_RELIC_APP_NAME"] = Settings.newrelic[:app_name]

    # Logfile
    ENV["NEW_RELIC_LOG"] = Settings.at(:logs, :newrelic)
  else
    ENV["NEWRELIC_AGENT_ENABLED"] = "false"
  end

  # That's it!
end

#newrelic_enabled?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rest-ftp-daemon/settings.rb', line 20

def newrelic_enabled?
  Settings.at(:newrelic)
end

#overwrite(options) ⇒ Object



54
55
56
# File 'lib/rest-ftp-daemon/settings.rb', line 54

def overwrite options
  Settings.merge!(options) if options.is_a? Enumerable
end