Sha256: f94ba8d0d6b9e2c6c880bb2f3dbd5c716de62ae771e161ac7cb37237ac578b70

Contents?: true

Size: 981 Bytes

Versions: 1

Compression:

Stored size: 981 Bytes

Contents

require "rails"
require "dryad"

module Dryad
  module Consul
    class Railtie < Rails::Railtie
      initializer "dryad_consul.set_consul" do
        ActiveSupport.on_load(:dryad_consul) do
          Dryad::Consul.configure_consul(Dryad.configuration)
        end
      end

      initializer "dryad_consul.update_active_record_connection" do
        config.after_initialize do
          db_path = "#{Dryad.configuration.namespace}/#{Dryad.configuration.group}/database.yml"
          begin
            db_config = Dryad::Consul::ConfigProvider.load(db_path)
            ActiveRecord::Base.configurations = YAML.load(ERB.new(db_config.payload).result)
            ActiveRecord::Base.establish_connection(Rails.env.to_sym)
          rescue Dryad::Core::ConfigurationNotFound => e
            raise e
          rescue Exception => e
            Rails.logger.warn e.message
          end
        end
      end
    end
  end
  ActiveSupport.run_load_hooks(:dryad_consul, Consul)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dryad-consul-0.2.7 lib/dryad/consul/railtie.rb