Module: ClusterPoint::Configuration

Included in:
ClusterPointAdapter
Defined in:
lib/cluster_point/configuration.rb

Instance Method Summary collapse

Instance Method Details

#get_base_uri(config) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/cluster_point/configuration.rb', line 27

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

#load_configObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cluster_point/configuration.rb', line 5

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