Sha256: 3158339e2867b700b5a422046431759b99afc8d0db102ac24187fb93a64aa656

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 KB

Contents

require "settingslogic"

# Configuration class
class Settings < Settingslogic
  # Read configuration
  namespace APP_ENV
  source File.exist?(APP_CONF) ? APP_CONF : Hash.new
  suppress_errors true

  # Direct access to any depth
  def at *path
    path.reduce(Settings) { |m, key| m && m[key.to_s] }
  end

  # Dump whole settings set to readable YAML
  def dump
    to_hash.to_yaml(indent: 4, useheader: true, useversion: false )
  end

  def newrelic_enabled?
    Settings.at(:newrelic)
  end

  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

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

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.250.0 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.247.1 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.247.0 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.246.1 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.246.0 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.245.1 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.245 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.243.2 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.243.1 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.243 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.242.5 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.242.4 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.242.3 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.242.2 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.242.1 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.242.0 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.241 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.240.2 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.240.1 lib/rest-ftp-daemon/settings.rb
rest-ftp-daemon-0.240.0 lib/rest-ftp-daemon/settings.rb