Sha256: bbb5d388382ad3ad1759bb399fa85f6c4a516aafe01c900e0acfc798378d1d16

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

module Lopata
  module Config
    extend self

    attr_accessor :build_number, :lopata_host, :lopata_code, :only_roles, :role_descriptions, :after_as, :ops

    def init(env)
      require 'yaml'
      @config = YAML::load(File.open("./config/environments/#{env}.yml")) || {}
      init_db
      @role_descriptions ||= {}
      # init_includes
    end

    def [](key)
      @config[key]
    end

    %w{url name readonly}.each do |opt|
      define_method opt do
        raise "Lopata::Config unititlalized, use Lopata::Config#init(env) to set environment" unless @config
        @config[opt]
      end
    end

    def init_db
      ActiveRecord::Base.establish_connection(@config['db']) if @config['db']
    end

    def init_rspec
      require 'lopata/rspec/dsl'
      require 'lopata/rspec/role'
      ::RSpec.configure do |c|
        c.include Lopata::RSpec::DSL
        c.include Lopata::RSpec::Role
      end
    end

    def init_active_record
      require 'lopata/rspec/ar_dsl'
      ::RSpec.configure do |c|
        c.include Lopata::RSpec::AR::DSL
      end
    end

    def init_lopata_logging(build)
      self.build_number = build
      ::RSpec.configure do |c|
        require 'lopata/rspec/formatter' # class cross-loading, avoid auto-loading
        c.add_formatter Lopata::RSpec::Formatter
      end
    end

    def init_rerun
      ::RSpec.configure do |c|
        c.inclusion_filter = { full_description: build_rerun_filter_proc }
      end
    end

    def build_rerun_filter_proc
      to_rerun = Lopata::Client.new(Lopata::Config.build_number).to_rerun
      Proc.new do |desc|
        to_rerun.include?(desc)
      end
    end

    def before_start(&block)
      @before_start = block
    end

    def initialize_test
      @before_start.call if @before_start
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lopata-0.0.12 lib/lopata/config.rb
lopata-0.0.11 lib/lopata/config.rb
lopata-0.0.10 lib/lopata/config.rb