Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Minor change in locating config file #68

Merged
merged 1 commit into from

2 participants

@Oscil8
Collaborator

A version of this resolved issues we had when deploying Vanity.

@assaf assaf merged commit 32fa7c8 into assaf:master
@assaf
Owner

Thanks, queueing for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 1, 2011
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 8 deletions.
  1. +20 −8 lib/vanity/playground.rb
  2. +1 −0  test/metric/remote_test.rb
View
28 lib/vanity/playground.rb
@@ -26,9 +26,9 @@ def initialize(*args)
# In the case of Rails, use the Rails logger and collect only for
# production environment by default.
defaults = options[:rails] ? DEFAULTS.merge(:collecting => ::Rails.env.production?, :logger => ::Rails.logger) : DEFAULTS
- if File.exists?("config/vanity.yml")
+ if config_file_exists?
env = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
- config = YAML.load(ERB.new(File.read("config/vanity.yml")).result)[env]
+ config = load_config_file[env]
if Hash === config
config = config.inject({}) { |h,kv| h[kv.first.to_sym] = kv.last ; h }
else
@@ -193,7 +193,7 @@ def metrics
Dir[File.join(load_path, "metrics/*.rb")].each do |file|
Metric.load self, @loading, file
end
- if File.exist?("config/vanity.yml") && remote = YAML.load(ERB.new(File.read("config/vanity.yml")).result)["metrics"]
+ if config_file_exists? && remote = load_config_file["metrics"]
remote.each do |id, url|
fail "Metric #{id} already defined in playground" if metrics[id.to_sym]
metric = Metric.new(self, id)
@@ -245,21 +245,21 @@ def establish_connection(spec = nil)
disconnect! if @adapter
case spec
when nil
- if File.exists?("config/vanity.yml")
+ if config_file_exists?
env = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
- spec = YAML.load(ERB.new(File.read("config/vanity.yml")).result)[env]
+ spec = load_config_file[env]
fail "No configuration for #{env}" unless spec
establish_connection spec
- elsif File.exists?("config/redis.yml")
+ elsif config_file_exists?("redis.yml")
env = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
- redis = YAML.load(ERB.new(File.read("config/redis.yml")).result)[env]
+ redis = load_config_file("redis.yml")[env]
fail "No configuration for #{env}" unless redis
establish_connection "redis://" + redis
else
establish_connection :adapter=>"redis"
end
when Symbol
- spec = YAML.load(ERB.new(File.read("config/vanity.yml")).result)[spec.to_s]
+ spec = load_config_file[spec.to_s]
establish_connection spec
when String
uri = URI.parse(spec)
@@ -272,6 +272,18 @@ def establish_connection(spec = nil)
end
end
+ def config_file_root
+ (defined?(::Rails) ? ::Rails.root : Pathname.new(".")) + "config"
+ end
+
+ def config_file_exists?(basename = "vanity.yml")
+ File.exists?(config_file_root + basename)
+ end
+
+ def load_config_file(basename = "vanity.yml")
+ YAML.load(ERB.new(File.read(config_file_root + basename)).result)
+ end
+
# Returns the current connection. Establishes new connection is necessary.
#
# @since 1.4.0
View
1  test/metric/remote_test.rb
@@ -10,6 +10,7 @@
sandbox: http://api.vanitydash.com/metrics/sandbox
RUBY
end
+ ::Rails.stubs(:root).returns(Pathname.new(File.expand_path("tmp")))
Dir.chdir "tmp" do
Vanity.playground.load!
end
Something went wrong with that request. Please try again.