Sha256: baee38b5491def8ee46dcc1c4bf2ee09b6e922c4022a97650b911836e3a3039d

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

require 'yaml'
require 'rails'
module ClusterPoint
  module Configuration
    def load_config
      @file = (Rails.root ? Rails.root.to_s : ".") + "/config/cluster_point.yml"
      @env = DEFAULT_ENV.call.to_s
      if !File.exists?(@file)
        raise ConfigurationNotFound
      end
      begin
        data = YAML.load_file(@file)
      rescue ArgumentError, Psych::SyntaxError => error
        raise Fixture::FormatError, "a YAML error occurred parsing #{@file}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n  #{error.class}: #{error}", error.backtrace
      end
      if !data.has_key?(@env)
        raise ConfigurationNotFound
      end
      @config = data[@env]

      self.class.base_uri get_base_uri(@config)
      if @config["debug_output"]
        self.class.debug_output $stdout
      end
    end

    def get_base_uri(config)
      host = config["url"] ? config["url"].sub(/(\/)+$/,'') : "https://api.clusterpoint.com"
      if !config.has_key?("account_id")
        raise AccountIdNotFound
      end
      if !config.has_key?("database")
        raise DatabaseNotSet
      end
      host + "/" + config["account_id"].to_s + "/" + config["database"].to_s
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clusterpoint-0.2.4 lib/cluster_point/configuration.rb
clusterpoint-0.2.3 lib/cluster_point/configuration.rb