Sha256: 31ec92f31d664a948e6d939c947eaf48be21247920a4b82c5e523a9a3fa15662

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

module NdrStats
  # Behaviour that runs when this gem is used in the context of a Rail app.
  class Railtie < Rails::Railtie
    # Auto-configures NdrStats with config in the host app, if found.
    config.after_initialize do
      config_file = Rails.root.join('config', 'stats.yml')
      next unless File.exist?(config_file)

      config = YAML.load_file(config_file).symbolize_keys.
               slice(:host, :port, :system, :stack).
               reject { |_, value| value.blank? }

      # Try and derive system/stack from applications that expose it:
      app_class = Rails.application.class
      host_module = app_class.try(:module_parent) || app_class.parent
      config[:system] ||= host_module.try(:flavour) || host_module.name.downcase
      config[:stack] ||= host_module.try(:stack) || Rails.env

      NdrStats.configure(**config)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ndr_stats-0.2.1 lib/ndr_stats/railtie.rb