Sha256: 2a1a374f45e7b1613b4682e6595cc94056b895392c9a569ea0286651b017d07d

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

module Larva
  class Configurator

    def self.configure(options = {})
      c = new(options)
      c.configure
      c
    end

    def initialize(options = {})
      @options = options
      @config_dir = options.fetch(:config_dir) {raise LarvaError.new("Please provide :config_dir via options")}
      @logfile = options.fetch(:logfile) {raise LarvaError.new("Please provide :logfile via options")}
      @env = (options[:env] || "development").to_s
    end

    def configure
      Filum.setup(@logfile)
      Filum.logger.info "Configuring Daemon"

      if propono_config = parse_config_file('propono.yml')
        Propono.config do |config|
          config.use_iam_profile  = propono_config[:use_iam_profile]
          config.access_key       = propono_config[:access_key]
          config.secret_key       = propono_config[:secret_key]
          config.queue_region     = propono_config[:region]
          config.application_name = propono_config[:application_name]
          config.queue_suffix     = propono_config[:queue_suffix]
          config.udp_host         = "pergo.meducation.net"
          config.udp_port         = "9732"
          config.logger           = Filum.logger
        end
      end

      after_configure if respond_to?(:after_configure)
    end

    private
    def parse_config_file(filename)
      contents = File.read("#{@config_dir}/#{filename}")
      hash = YAML::load(contents)
      hash.stringify_keys[@env].symbolize_keys
    rescue
      nil
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
larva-1.1.3 lib/larva/configurator.rb
larva-1.1.2 lib/larva/configurator.rb
larva-1.1.1 lib/larva/configurator.rb
larva-1.1.0 lib/larva/configurator.rb
larva-1.0.1 lib/larva/configurator.rb
larva-1.0.0 lib/larva/configurator.rb