Sha256: 7ef84782882682a728800f36b2d9e75c82c7cf502265210adee8874096d08027

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

lib = File.expand_path(File.join(File.dirname(__FILE__),'../lib'))
$:.unshift(lib) unless $:.include?(lib)

require 'yaml'
require 'cucumba/railz'

module Cucumba

  class ConfigNotFound < StandardError
  end

  # Usage:
  #
  #   Cucumba[:main]
  # or
  #
  #   Cucumba['main']
  #
  # where :main('main') is the
  # server name in config file.
  # Return Cucumba client instance
  def self.[] server_name
    server_name = server_name.to_s
    if server_name == "_self_"
      Cucumba::Railz.new(config.first)
    else
      Cucumba::Railz.new(config_for(server_name))
    end
  end

  private

  def self.config_for server_name
    config.each do |server_config|
      if server_config[:name]==server_name
	return server_config
	break
      end
    end
    raise Cucumba::Railz::ServerNotFound, "server with name '#{server_name}' not described in config file"
  rescue Errno::ENOENT  # yml file not found
    raise ConfigNotFound, "config not found, run 'cucumba' generator"
  end

  def self.config
    @@config ||= YAML.load_file(File.join((defined?(::Rails) ? ::Rails.root.to_s : Dir.pwd),'config','cucumba.yml'))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cucumba-0.0.6 lib/cucumba.rb